How-to articles, tricks, and solutions about PYTHON
How do I print the key-value pairs of a dictionary in python
You can use the items() method to print the key-value pairs of a dictionary in Python.
How do I print to stderr in Python?
To print to stderr in Python, you can use the stderr attribute of the sys module:
How do I read CSV data into a record array in NumPy?
You can use the numpy.genfromtxt() function to read CSV data into a NumPy record array.
How do I remove duplicates from a list, while preserving order?
There are several ways to remove duplicates from a list while preserving order.
How do I remove the first item from a list?
You can use the list method pop(index) to remove the first item in a list.
How do I remove/delete a folder that is not empty?
You can use the shutil module in Python to remove a folder that is not empty.
How do I reverse a string in Python?
To reverse a string in Python, you can use the following method:
How do I select rows from a DataFrame based on column values?
You can use the DataFrame.loc method to select rows from a DataFrame based on column values.
How do I sort a dictionary by key?
In Python, dictionaries are unordered collections of key-value pairs.
How do I split a string into a list of characters?
In Python, you can use the built-in list() function to convert a string into a list of characters.
How do I split a string into a list of words?
Here is an example of how to split a string into a list of words in Python:
How do I split the definition of a long string over multiple lines?
You can split a string over multiple lines by using triple quotes, either ''' or """ .
How do I terminate a script?
In Python, you can terminate a script by using the exit() function from the sys module.