>>> d = {'a': 1, 'c': 3, 'b': 2} {'a': 1, 'c': 3, 'b': 2} >>> [(k,v) for k, v in d.items() if k == 'a' or k == 'b'] [('a', 1), ('b', 2)] >>> j = [(k,v) for k, v in d.items() if k == 'a' or k == 'b'] >>> j [('a', 1), ('b', 2)] >>> dict(j) {'a': 1, 'b': 2} >>>
No comments:
Post a Comment