python_codes | Unsorted

Telegram-канал python_codes - Python Codes

-

This channel will serve you all the codes and programs which related to Python. We post the codes from the beginner level to advance level. Admin : @Only_Mahi

Subscribe to a channel

Python Codes

Share and Support
@Python_Codes

Читать полностью…

Python Codes

💡🐍 Did you know?

You can use slices in Python to insert elements to a list in arbitrary positions?


Share and Support
@Python_Codes

Читать полностью…

Python Codes

Do you want to know the recursion limit in Python?


Share and Support
@Python_Codes

Читать полностью…

Python Codes

round() function

the round function is used to convert the floating-point into a specified number of decimals number

@Python_Codes

Читать полностью…

Python Codes

Most of the time, we don't want to share our wifi passwords, in that case, we generate a QR and stick it on the wall.

@Python_Codes

Читать полностью…

Python Codes

With cache

@Python_Codes

Читать полностью…

Python Codes

Use functools.cache to add a simple cache to your Python 🐍 functions.

@Python_Codes

Читать полностью…

Python Codes

Python Tip:

You can use the calendar module in one line from the command line with python -m calendar

@Python_Codes

Читать полностью…

Python Codes

Python Class Anatomy

Almost everything a Python class definition can contain summed up in one image :)

@Python_Codes

Читать полностью…

Python Codes

Summarize any website content in just a few lines of Python code.

@Python_Codes

Читать полностью…

Python Codes

Program to create a Countdown Timer

@Python_Codes

Читать полностью…

Python Codes

The simplest way to flatten a list in python.


@Python_Codes

Читать полностью…

Python Codes

3 Ways to merge Dictionaries in python

@Python_Codes

Читать полностью…

Python Codes

Indian Flag Using Python

@Python_Codes

Читать полностью…

Python Codes

Difference between list and tuple in python

🔸List is mutable ( you can modify the original list) and it's values are written in sqare brackets [ ]

🔸Tuple is immutable ( you can't modify it) and it's values are written in parentheses ( ) delimited by comma( , )

🔸To convert list to tuple - we use tuple() function
list1 = [1,2,3]
print(tuple(list1)) Output : (1,2,3)

🔸 For single element list
list1 = [1]
print(tuple(list1)) Output : (1, )

▪️a tuple is a tuple because of comma not because of parentheses


@Python_Codes

Читать полностью…

Python Codes

Common techniques for using the set() function in Python:

1. Create a set from a list:

my_list = [1, 2, 2, 3, 3, 3]
my_set = set(my_list)


2.Add an item to a set:

my_set = {1, 2, 3}
my_set.add(4)


3.Remove an item from a set by its value:

my_set = {1, 2, 3}
my_set.remove(3)


4.Check if an item is in a set:

my_set = {1, 2, 3}
if 3 in my_set:
print("The item is in the set.")


5.Get the length of a set:

my_set = {1, 2, 3}
set_length = len(my_set)


6.Loop through the items in a set:

my_set = {1, 2, 3}
for item in my_set:
print(item)


7.Get the union of two sets:

set1 = {1, 2, 3}
set2 = {3, 4, 5}
union_set = set1.union(set2)


8.Get the intersection of two sets:

set1 = {1, 2, 3}
set2 = {3, 4, 5}
intersection_set = set1.intersection(set2)

Share and Support
@Python_Codes

Читать полностью…

Python Codes

What are pure functions?

A pure function is a function that will return the same value given the same arguments. A function is not pure if there is something outside the function that can change its return value, given the same arguments.


Share and Support
@Python_Codes

Читать полностью…

Python Codes

How do you check if an array is monotonic?

An array is monotonic if the elements are sorted either in descending order or ascending order.

Share and Support
@Python_Codes

Читать полностью…

Python Codes

any() function returns True if at least one item is True in the iterable object.

@Python_Codes

Читать полностью…

Python Codes

How to convert a CSV file to MS Excel with Python and OpenPyXL

@Python_Codes

Читать полностью…

Python Codes

Without cache

@Python_Codes

Читать полностью…

Python Codes

Multiple Adjacent String Literals in python

@Python_Codes

Читать полностью…

Python Codes

Python Tip:

You can use dict on a class instance to get all instance attributes as a dictionary

@Python_Codes

Читать полностью…

Python Codes

💡 Python Life Hack: Do you know you can copy the files from a computer to a mobile phone 📱 without any cable using Python 🐍 ?

@Python_Codes

Читать полностью…

Python Codes

💡 Python Tip: Do you know Ellipsis(...) can be used as a placeholder in Python, just like a 𝘱𝘢𝘴𝘴 statement?

@Python_Codes

Читать полностью…

Python Codes

Useful Pandas🐼 method you should definitely know

✅ head()
✅ info()
✅ fillna()
✅ melt()
✅ pivot()
✅ query()
✅ merge()
✅ assign()
✅ groupby()
✅ describe()
✅ sample()
✅ replace()
✅ rename()


@Python_Codes

Читать полностью…

Python Codes

Do you know abou .strip()

From the above example you can see that it removed all the characters mentioned in .strip('comw.') and returns the remaining string


@Python_Codes

Читать полностью…

Python Codes

To shuffle pandas DataFrame df (in a reproducible way):

df = df.sample(frac=1, random_state=123).reset_index(drop=True)

Alternatively, you can use sklearn.utils.shuffle().

#pandas

@Python_Codes

Читать полностью…

Python Codes

Guess the Number Game in Python

@Python_Codes

Читать полностью…

Python Codes

What Is FastAPI?

FastAPI is a modern, high-performance web framework for building APIs with Python based on standard type hints.


It has the following key features:

👉Fast to run: It offers very high performance, on par with NodeJS and Go, thanks to Starlette and pydantic.

👉Fast to code: It allows for significant increases in development speed.

👉Reduced number of bugs: It reduces the possibility for human-induced errors.

👉Intuitive: It offers great editor support, with completion everywhere and less time debugging.

👉Straightforward: It’s designed to be uncomplicated to use and learn, so you can spend less time reading documentation.

👉Short: It minimizes code duplication.

👉Robust: It provides production-ready code with automatic interactive documentation.

👉Standards-based: It’s based on the open standards for APIs, OpenAPI and JSON Schema.

You can use this instead of Django and Flask

Share and Support
@Python_Codes

Читать полностью…
Subscribe to a channel