eEcho blog

is een halte van de gedachte

Python Dictionary Access

u = c[’uid’] # Get an element

c[’shell’] = "/bin/sh" # Set an element

if c.has_key("directory"): # Check for presence of an member
   d = c[’directory’]
else:
   d = None
   d = c.get("directory",None) # Same thing, more compact

Doorbladeren

>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}
>>> for k, v in knights.iteritems():
…       print k, v

gallahad the pure
robin the brave

>>> for i, v in enumerate(['tic', 'tac', 'toe']):
…    print i, v

0 tic
1 tac
2 toe

Add A Comment

You must be logged in to post a comment.

Home | info@eecho.info | Voorwaarden | Blog