#Python includes a `format()` function that is built-in. This function is very similar to the string's `format()` method, but is more low-level than that method
Today I am going to show you how to create 7οΈβ£ different file types with #Python:
π Text file
π CSV
π XML
π JSON
π Tar file
π PDF
π Excel
Join me for this fun π§΅π
1οΈβ£ Creating a text file with #Python is a breeze! The recommended method is to use Python's `with` statement as it will automatically close the file for you
That means you can create a text file with TWO lines of code if you want to:
2οΈβ£ Creating a CSV file with #Python can be accomplished using the `csv` module
Another great tool in #Python's `collections` module is the `defaultdict`! ππ₯
`defaultdict` is a subclass of the built-in dict class where the first argument is a factory attribute.
π§΅ππ
Let's start out by creating a regular dictionary so you can see how `defaultdict` might help clean up your code.
Here you create a dictionary based on words in a string using a conditional statement to add the various words.
You can also see the output in the 2nd screenshot
Now if you use a `defaultdict` with an `int` factory, you can get rid of the conditional statement entirely, which makes your code shorter and easier to read! ππ₯