Table of contents One item at a time Pickle object serialization Write string to file Write json to file Write lines Using print List to string References Save list to file in Python Saving data structures such as lists to permanent storage for later retrieval is a common practice in computer programming. This technique is
Introduction Today, we are going to talk about directories, files and paths in Python. If you are in rush and only need to know the syntax, here is how to get the current working directory… For more information, continue reading… Python provides dedicated cross platform modules to interface with the operating system and file system.
Introduction This is going to be a compact post. Did the title catch your attention? Actually, It was intentional as we could have named it list comprehensions in Python. Looping in Python is awesome, if you are curious, you may check this post for more details about loops. In this post, we are only going
Introduction Copying data structures such as lists is a frequently performed task in computer programming. For instance, one of the most efficient sorting algorithms is merge sort. Merge sort uses divide and conquer approach to split the unsorted list into two sections in a recursive fashion. To do so, merge sort uses list copying technique.
Introduction In this Python code snippet, we are going to implement an easy hangman solver using simple source code. The game code is adapted to work with both Python 2.x and Python 3.x. The example provided is a console based application for beginners. Let us get started with the tutorial… Python 2.x program There is
Introduction Ready for more code snippets? In this post, we are going to talk about random numbers in Python. Have you ever thought about what random means or even if randomness makes any sense in the context of computing! (as computers execute instructions blindly). Is randomness useful? can we apply it in real life computational
Introduction Unicode is an important topic in computing but it is a little bit confusing. In particular, it can be more confusing in the context of Python programming language. For that reason, the aim of our article today is to clarify the ambiguity and hopefully put things into perspective. Beginners may get confused because they
Introduction It is hard (even impossible) to find a real world application not using string comparison. It can be used in database lookup, searching for files on disk, sorting contacts and many other scenarios. String comparison in Python is not hard as we will demonstrate in today’s code snippets. Let us get started… Python string
Introduction Today, we are going to discuss how to convert numbers to strings and visa versa. It is a straightforward Python topic but it is important as well. There are various real life scenarios where type conversion is required. Before elaborating more, let us mention two example use cases to get a taste of what
Table of contents Introduction What is a regular expression? What is Python raw string? Python RE module Python regular expressions syntax summary Regular expressions flags re.match re.search Why use re.match? Regular expression compilation re.match and re.search examples re.fullmatch Match objects re.findall re.finditer re.split re.sub Summary References Introduction Welcome to a new Python code snippets post.