Function json.loads() accepts JSON string and converts it to Python dictionary (deserialization). The last letter in load(s) stands for “string”.
Continue readingAuthor Archives: Tomasz Decker
How to Write to Text File in Python
To write to a text file in Python, you have to use the open() and write() functions. The open() function takes two parameters: file name and file access mode. The returned value of open() is the file object.
Continue readingConvert CSV to a dictionary in Python
To use CSV files in Python, you have to import the CSV module. It offers functions that can read the file (csv.reader) or read and map it to a dictionary (csv.DictReader).
Continue readingGet an Index of a String or Character in Python
The index and find functions return the position of a character or a substring inside a string. They both take a single parameter, that is required. The two additional parameters: __start and __end are optional.
Continue readingFind an Index of an Item in a List in Python
The index function returns the position of an item in a list. The function takes up to three parameters. One of them is required and the other two are optional.
Continue readingMultiply Each Element of a List Python
When you multiply each element of a list, you create a new list with each value from the original list multiplied by a specific number.
Continue readingConvert Range to a List in Python
If you need to create a list from range, you can use the list constructor. This constructor will convert a range into list elements.
Continue readingConvert Excel Spreadsheet to JSON in Python
To convert an Excel spreadsheet into JSON, first, you have to import the necessary modules: one for reading an Excel file and the second one for converting this data into the JSON format.
Continue readingCheck if a String is Empty in Python
The easiest way to check whether the string is empty is to use the len function. This function is going to return the length of a string.
Continue readingRange of a List in Python
The slice notation in Python is easy to understand. If you want to get a range of a list, you have to give the start and end value.
Continue reading