Python Morsels
@PythonMorsels
Followers
7K
Following
58
Media
152
Statuses
2K
Giving life-long learners a low-stress way to hone their #Python skills. 🐍🍪 Write beautiful code. ✨ Made by @treyhunner 💖
Joined January 2018
Python Morsels gives professional developers a low-stress way to hone their Python skills, through weekly screencasts and exercises. 🐍🍪 It's not a course. And it's not for complete beginners. Try it out: https://t.co/ylveRTs3Tm More details 👇 https://t.co/cOaB9A8kOY
pythonmorsels.com
Practice a new intermediate-level Python concept every week
Looking for an excuse to deepen your #Python skills? I made @PythonMorsels for you. It's not an Intro to Python course. It's both not a course & includes topics well beyond introductory Python. Don't think "tennis class". Think "weekly tennis practice". 🎾 But for Python! 🐍
1
5
23
"A yield statement turns a regular function into a generator function." #Python
https://t.co/VC1kpPy9ot
pythonmorsels.com
When you call a generator function it doesn't actually run the function; instead it returns a generator object.
0
0
3
You'll almost always see tuple unpacking used whenever enumerate is used. for n, fruit in enumerate(favorite_fruits, start=1): print(n, fruit) #Python
https://t.co/s1fDQDtkgF
pythonmorsels.com
Python's built-in enumerate function is the preferred way to loop while counting upward at the same time. You'll almost always see tuple unpacking used whenever enumerate is used.
0
1
3
You don't need third-party libraries to read CSV files in #Python! Python's csv module includes helper functions for reading CSV files, tab-delimited files, and other delimited data files. 👀💻🔍 https://t.co/Rny3bJv3h4
pythonmorsels.com
You don't need third-party libraries to read CSV file in Python! Python's csv module includes helper functions for reading CSV files, tab-delimited files, and other delimited data files.
0
0
4
"When we call this generator function, it doesn't actually run the code in that function!" 🤯 #Python
0
0
5
"When we loop over a csv.reader object, the reader will loop over the file object that we originally gave it and convert each line in our file to a list of strings." 🔄💱 #Python
https://t.co/Rny3bJv3h4
pythonmorsels.com
You don't need third-party libraries to read CSV file in Python! Python's csv module includes helper functions for reading CSV files, tab-delimited files, and other delimited data files.
0
0
7
"We can only tell it's a generator function by the presence of a yield statement." #Python
https://t.co/VC1kpPy9ot
pythonmorsels.com
When you call a generator function it doesn't actually run the function; instead it returns a generator object.
0
0
3
"Creating a singleton class might seem a little bit misleading to someone using this class." 😖 #Python
https://t.co/CdzeJXElkX
0
1
4
"Note that csv.reader doesn't know or care about the headers in our file: it treats every row equally." #Python
https://t.co/Rny3bJv3h4
pythonmorsels.com
You don't need third-party libraries to read CSV file in Python! Python's csv module includes helper functions for reading CSV files, tab-delimited files, and other delimited data files.
0
3
6
"The yield statement is what turns a function into a generator function." 🔻 #Python
https://t.co/iaFc8opnQi
0
1
6
"We've exhausted our generator object; we've fully consumed all the items within it." 🏁 #Python
https://t.co/iaFc8opnQi
0
1
7
"Unlike lists, generator objects don't have a length" #Python
https://t.co/NuxZwW91wO
pythonmorsels.com
List comprehensions make lists; generator expressions make generators. Generators are lazy single-use iterables which generate values as you loop over them.
0
2
8
If something is important, it deserves a name. #Python's for loops names the items themselves, not indexes. https://t.co/57ciUT7p4o
pythonmorsels.com
Unlike traditional C-style for loops, Python's for loops don't have indexes. It's considered a best practice to avoid reaching for indexes unless you really need them.
0
0
1
"For a very simple command-line program, you could just rely on #Python to close the file automatically when your Python program exits." https://t.co/kaY154UV3n
0
0
2
"In #Python, you can customize what happens when you ask objects whether they're equal to each other." 🐍🟰 https://t.co/5hWaEviOt9
pythonmorsels.com
Want to customize what "equality" means for your class instances in Python? Implement a __eq__ method! Make sure to return NotImplemented as appropriate though.
0
1
4
If we want to start counting at a different number, we can set the start keyword argument when calling enumerate. for n, fruit in enumerate(favorite_fruits, start=1): print(n, fruit) #Python
https://t.co/s1fDQDtkgF
pythonmorsels.com
Python's built-in enumerate function is the preferred way to loop while counting upward at the same time. You'll almost always see tuple unpacking used whenever enumerate is used.
0
0
5
The built-in str function actually calls the __str__ method on the object that we give it. #Python
https://t.co/p9ChRPCaVp
0
2
7
"If you'd prefer to think in terms of the headers in your file, rather than in terms of the indexes of each data column, you could use csv.DictReader instead of csv.reader." 📚 #Python
https://t.co/Rny3bJv3h4
pythonmorsels.com
You don't need third-party libraries to read CSV file in Python! Python's csv module includes helper functions for reading CSV files, tab-delimited files, and other delimited data files.
0
0
3
"Just like with reader objects, we can loop over DictReader objects to get the rows within our file. But unlike reader objects, instead of getting back lists representing each row, we'll get back dictionaries." #Python
https://t.co/Rny3bJv3h4
pythonmorsels.com
You don't need third-party libraries to read CSV file in Python! Python's csv module includes helper functions for reading CSV files, tab-delimited files, and other delimited data files.
0
0
3
"A singleton class is a class that only allows creating one instance of itself." 1️⃣ #Python
https://t.co/CdzeJXElkX
0
2
4
"Turn a regular function into a generator function by replacing append calls with yield statements." 🐍 #Python
https://t.co/5MgLLRq7gC
pythonmorsels.com
Have a function that returns a list? You may be able to turn it into a generator function by replacing the append calls with yield statements.
1
0
3