1.Iterators
a container can procide an iteartor that provides acceess to its elements in some order.
iter(iterable)
next(iterator)
>>>s = [[1, 2], 3, 4, 5]
>>>next(s)
Error
>>>t = iter(s)
>>>next(t)
[1, 2]
>>>next(t)
3
>>list(t)
[4, 5]
2.View of a dictionary
an iterable value is ant value that can be passed to iter to produce an iterator
an iterator is returned from iter and can be passed to next;all iterators are mutable
a dictionary, its keys, its values and its items are all iterable values
the order of items in a dictionary is the order in which they were added
historically items apppeared in an arbitrary order(python 3.5 and earlier)
3.for statement
4.buit-in iterator functions
many built-in python sequence operation return iterators that compute results lazily(not immediately, only when you call the value)
>>>bcd ['b'. 'c'. 'd']
>>>map(lambda x: x.upper(), bcd)
>>>m = map(lambda x: x.upper(), bcd)
>>>next(m)
'B'
>>>t = [1, 2, 3, 2, 1]
>>>reversed(t)
<list_reverseiterator object at 0x101b7ad30>
>>>reversed(t) == t
False
>>>list(reversed(t))
[1, 2, 3, 2, 1]
>>>list(reversed(t)) == t
True
"""because reversed(t) is a iterator but not a list"""
5.generators and generator functions
a generator function is a function that yields vaaluse instead of returning them
a normal function returns once;a generator fnction can tield mutiple times
a generator is an iterator create automatically by calling a generator function
when agenerator gunction is called, it returns a generator thay iterates over its yields
6.generators can yield from iterators
a yield from tatement yields all values from an iterator or iterable
when meet yield value pause and return
when next calling, continue from the pause place