Python tips and tricks
Data is the new oil. In the 21st century, you all know that how AI is impacting our daily routines. Data Science is the most demanded and pursued field. When we consider the skills needed to become a Data Scientist or Data Engineer, or Data Analyst we must at least know one programming language. In all job descriptions python is the most mentioned programming language. Python is open-source, easily interpretable, and similar to writing in English.
In this post, I will discuss some of the techniques that I have used in my projects and learned through online platforms.
01. Using max and min
To find out the maximum and minimum value in a list you can use max and min inbuilt python packages.
02. List Comprehension
List comprehensions provide a concise way to create lists. It’s one of the best features of python.
Here nums is a python list
List comprehension with filter
03. Iterate with enumerate
If you working with a list and you want to track the list element and also the index of the element instead of range length you can try with enumerate. See the code snippets below.
04. Sort in-built function
Using sort in-built function you can iterate complex iterables. You can use the reverse argument to descend the output.
05. Store unique values in sets
Set is an unordered data collection type. If you have a list with duplicate elements the nice way to remove duplicates is to convert the list into a set and then again convert it into a set to list.
06. Dict Comprehension
Like list comprehension you can perform dictionary comprehension in python. see the below code snippet to get the dict comprehension expression.
07. Map () Function
The above syntax is for map function. It takes two arguments function and iterables and returns map object. After that, we need to convert into other python data types such as lists, sets, and tuples.
Take this example, if we have a list with numbers and want to get the cubic values of each value in the list we can try with a map function to get the answer. See the below code snippet.
08. Metta Classes in Python
Creating python class using type keyword.
09. F strings in Python
The formated string is a way to manipulate strings in python.
End
Thank you for reading my article and I hope you found this article useful! I have planned to continue this article by adding other techniques.
If there are tips you think I should want to include or other suggestions then please do comment.
Happy Learning! 💻