python - Call of sort method returns unexpected result -
i have dictionary:
{'three': 3, 'two': 2, 'one': 1} and need make operations tuple of keys dictionary, i'm trying use code:
list(d.keys()) # need sort list(d.keys()).sort() # why such construction returns none? (use print() track it) i'm using vs 2013 , intellisense prompts me sort method when print list(d.keys()). i'm missing?
p.s such construction works well:
l = list(d.keys()) l.sort() thank you!
the .sort() method modifies list in place , returns none. use on list returned method need save list in variable.
l = list(d.keys()) l.sort() print l if want eliminate temporary variable, use sorted:
print sorted(d.keys())
Comments
Post a Comment