Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #python working with dict
- from __future__ import print_function #Compatibilidade func print python 2/3
- #python dict
- d = {'id':1, 'name':'nome', 'desc':'descricao'}
- #Print keys and values of dict
- for key in d.keys():
- print (key, d[key])
- #Print keys and values of dict using items funcion
- # and formating string position
- for key, val in d.items():
- print (key.ljust(6), val)
- #check if dict has an key
- d.has_key('key') #only python 2
- 'key' in d.keys() #python 2,3
- #Remove key id
- d.pop('desc')
- #update dict
- new_dict = {'name':'Jose'}
- d.update(new_dict) #d = {'desc': 'descricao', 'id': 1, 'name': 'Jose'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement