How to write text files in Python 3?

Create text files using Python To create text files in Python, use the open built in function with two key parameters: the file path and the mode in which the file should be opened. Use ‘w’ as the mode value to open the file for writing. Once the file is opened, call the write() build-in … Read more

How to convert a Python string to Hex format?

Print strings to hexadecimal in Python You can use one of the following two methods to convert and print a python string as an hexadecimal: # 1: Using the int() function: Using int(string, base=16) , we can convert the string to an integer with base 16 (Hexadecimal). Once we have the integer, we can use … Read more

How to find unique occurrences in a Python list?

There are instances in which would like to remove duplicated items from your Python lists. Here are a few use cases that come to mind: In this post, we’ll introduce three different techniques to identify if we have any repeated values in the list and obtain a list of unique values that you can later … Read more

How to round a number or float list in Python?

Rounding float numbers in Python To handle rounding of floats, we use the built-in round() function or the decimal module. In case that we have an iterable such as a list or dictionary we can use a comprehension to round the iterable elements. Let’s look at more examples: Example 1: As we learned, Python has … Read more