Python: Find an Index (or all) of a Substring in a String
Learn how to find the index of the first or last substring of a string using Python. Also learn how to find all indices of a substring.
Learn how to find the index of the first or last substring of a string using Python. Also learn how to find all indices of a substring.
Learn how to print all of a Python object’s attributes using the dir() and vars() functions, and how to print pretty using the pprint module.
Learn how to split a Python list into n chunks, including how to split a list into different sized sublists or a different number of sublists.
Learn how to get all combinations of a Python list, including with substitution, using the helpful itertools library.
Learn how to remove a Python dictionary key, using the pop method, the del keyword, and how to remove multiple Python dictionary keys.
Learn how to use Python to flatten a list of lists, including using the itertools library, list comprehension, and multi-level lists of lists.
Learn how to create inline if statements in Python, often known as the Python ternary operator, allowing you to apply conditions inline.
In this post, you’ll learn how to use Python to remove newline characters from strings, including how to replace all or trailing newlines.
Learn how to use Python to get the last item from a list, or the last n items from a list, as well as how Python list indexing works.
Learn how to use Python to pretty print a JSON object, including from a file, from an API, and how to save the pretty output to a file.
Learn how to use Python to remove a character from a string, using replace and translate. Learn to limit removals and multiple characters.
Learn how to use Python to remove the first n characters from a string, including using indexing as well as the popular re module.