Practical solutions

Python How-To's How-To Guides

Solve the problem. Keep building. The collection of Python-related howtos

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

How to Sort List of Tuples in PythonThis tutorial demonstrates how to sort a list of tuples. How to Reverse a String in PythonIn Python, a string can be reversed using slicing, loop, reversed, recursive, and join methods. How to Declare 3D Array in PythonThere are 3 main methods that can be used to declare a 3D array in Python, the list comprehensions, the multiplication method, and the numpy package. How to Convert String to Hex in PythonThis tutorial demonstrates the various way on how to convert string to hexadecimal in Python. How to Calculate Percentile in PythonIn Python, the percentile of a one-dimensional integer array can be calculated using scipy and NumPy libraries, user-defined function, math package, statistics package, and interpolation method. How to Apply a Function to a List in PythonThere are 4 main methods that can apply a function to a list in Python; the for loop, the map() function, list comprehension, and generator expression. How to Iterate Through JSON Object in PythonThis tutorial demonstrates how to iterate through a JSON object in Python. How to Increment by 2 in Python for LoopIn Python, a loop can increment the values with the step size of 2. In this article, we will discuss the different methods of incrementing by 2 in a for loop using the range() function, the slicing method, and the += operator. How to Get Index of Maximum and Minimum Value of a List in PythonThere are 2 main methods that can be used to get the index of the maximum and minimum values of a list in Python, using the max() and min() functions with list.index() function and using the numpy.argmax() and numpy.argmin() functions. How to Generate a Random Prime Number in PythonIt demonstrates how to generate a random prime number in Python How to Convert a String to Binary in PythonIn Python, a string can be converted to its binary representation using the format(), map(), bytearray(), bin(), and ASCII methods. How to Comment a Block of Code in PythonIn this tutorial, we will discuss methods to comment out multiple lines of code in Python, like using # and triple quotes. How to Clear a List in PythonIt demonstrates how to clear a list in Python How to Calculate Time Elapsed in PythonThere are 3 methods inside the time module that can be used to calculate time in Python, the time(), the perf_counter(), and the process_time() functions. How to Append List to Another List in PythonIt demonstrates how to append a list into an existing list in Python. How to Add Key to a Dictionary in PythonThere are 2 main methods that can be used to add a key to a dictionary in Python, adding a new key/value pair and the dict.update() function. How to Write String to a File in PythonThere are 2 main methods that can be used to write a string to a file in Python, the file handling and the context manager. How to Remove Numbers From String in PythonThis tutorial demonstrates how to remove numbers or digits from the string in Python How to Remove NaN From List in PythonThis tutorial demonstrates how to remove NaN from the list in Python. How to Generate Random Strings in PythonThis tutorial demonstrates how to generate a random string in Python How to Convert Hex to ASCII in PythonThis tutorial explains the different ways to convert a hexadecimal string to ASCII in Python. How to Check List Equality in PythonThis tutorial demonstrates how to check whether the two lists are identical or equal in Python. The switch Statement in PythonThis tutorial demonstrates how to implement functionality of the switch statement in Python How to Split a String by WhiteSpace in PythonIt demonstrates how to split strings using whitespace in Python