Example:
>>> d = {'answer':1, 'Question':2}
>>> for i, j in sorted(d.items()): print i
Question
answer
I would like case insensitive list:
answer
Question
and I believe it can be done in simple Pythonic way.
If it's just about printing the keys:
for i in sorted(d.keys(), key=lambda x: x.lower()): print i
If you need the values afterwards, you could do
for i, j in sorted(d.items(), key=lambda x: x[0].lower()): print i, j
EDIT: Even shorter and better (since you have d in scope):
for i in sorted(d, key=str.lower):
print i, d[i]
import string
sorted(d.items(), key=string.lower)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With