Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # list_sort_from_dict.py -- dicts can not be inherently sorted as like lists and tuples, so...
- data = {'py123':'one','py456':'two-abc','xxx':'abc','xyz.py':'123py','Python!':'Easy as ABC'}
- print [x for x in list(data.keys()) if 'py' in x]
- print [data[x] for x in list(data.keys()) if 'py' in x]
- print [x for x in list(data.values()) if 'abc' in x]
- print [x for x in data if 'abc' in data[x]]
- print [(k,v) for k,v in data.items() if k.lower().startswith('py') and v.lower().endswith('abc')]
- d = {1: 2, 3: 4, 4: 1, 2: 3, 0: 0}
- print sorted(d.items(), key=lambda x: x[1])
- print d.items()
- # add_item_to_dict.py ...
- data = {
- 'item a': 1,
- 'item b': 2,}
- data['item c'] = 3
- data.update({'item d': 4,'item e': 5,'item f': 6})
- for i in data.items(): print i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement