Factor sorted into a function that returns a sorted copy: def sorted(seq): seq = list(seq) seq.sort() return seq or one that sorts in place: def sorted(seq): seq.sort() return seq Now you can write your one-liner: for i in sorted({}.keys()): ... Jeff