A Champion's Guide on Functional Programming
source link: https://hackernoon.com/a-champions-guide-on-functional-programming-2as33o5
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Note: Keep in mind that in an iterator, one can only go forward; you can’t get the previous part, copy it, or reset the iterator. These additional capabilities are optional for iterator objects, but the iterator protocol only specifies the __next__() method. The iterator protocol only specifies the __next__() method, so these additional capabilities are optional for iterator objects. Functions can thus consume the iterator’s entire output, and if you need to do something different with the same stream, you must create a new iterator.
DIFFERENT DATA TYPES THAT SUPPORTS ITERATOR
Now that we’ve already gone through how tuples and lists support iterators. When you call iter() on a dictionary, you get an iterator that loops through the dictionary’s keys:
Input:
m = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6,
... 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
for key in m:
print(key, m[key])
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK