Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print('-'*10)
- # Filtering out cyborgs with fuel usage equal to 3
- currentname = (cyborg['firstname'] for cyborg in cyborgs if cyborg['fuelusage'] == 3)
- #print(currentname) # Has error: <generator object <genexpr> at 0x10fa5bf50>
- print(next(currentname)) # Joshua
- print('type', type(currentname)) # ('type', <type 'generator'>)
- # Another way
- currentname = ([cyborg['firstname'] for cyborg in cyborgs if cyborg['fuelusage'] == 3])
- print(currentname) # ['Joshua']
- print(type(currentname)) # <type 'list'>
- #print(next(currentname)) # Has error: TypeError: list object is not an iterator
- currentname = str(currentname)
- print(type(currentname)) # <type 'str'>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement