Advertisement
Guest User

Untitled

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