What is the best way to sort a list of words with the case insensitive?
bumsfeld
413
Nearly a Posting Virtuoso
Recommended Answers
Jump to PostHi!
Since Python 2.4 (I guess it's 2.4), sort has the option key:
>>> import string >>> l = ["a","B","c","D"] >>> l.sort(key=string.lower) >>> l ['a', 'B', 'c', 'D']
Here's a way for < 2.4:
>>> l.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
Regards, mawe
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.