#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! 🐍🔥
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! 🐍🔥