Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. print('-'*10)
  2. # Filtering out cyborgs with fuel usage equal to 3
  3. currentname = (cyborg['firstname'] for cyborg in cyborgs if cyborg['fuelusage'] == 3)
  4. #print(currentname) # Has error: <generator object <genexpr> at 0x10fa5bf50>
  5. print(next(currentname)) # Joshua
  6. print('type', type(currentname)) # ('type', <type 'generator'>)
  7.  
  8. # Another way
  9. currentname = ([cyborg['firstname'] for cyborg in cyborgs if cyborg['fuelusage'] == 3])
  10. print(currentname) # ['Joshua']
  11. print(type(currentname)) # <type 'list'>
  12. #print(next(currentname)) # Has error: TypeError: list object is not an iterator
  13. currentname = str(currentname)
  14. print(type(currentname)) # <type 'str'>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement