[Tutor] printing answers

Rich Krauter rmkrauter at yahoo.com
Thu Feb 5 16:49:19 EST 2004


I think you are saying you want to eliminate
duplicates, without regard to case. That's what I do
below.

I think you're making it much harder than it needs to
be by using regexes and nested loops. 
Notice I use answers as a dict, not a list. Dicts are
nice when you want to get rid of repeats.

def findMatch(list_of_strings):
    answers = {} 
    for s in list_of_strings:
        try:
        	answers[s.lower()] += 1
        except:
                answers[s.lower()] = 1 
    print answers.keys()
    print answers

if __name__ == '__main__':
    list_of_strings = ['one','One', 'two',
'three','ThrEE']
    findMatch(list_of_strings)

Rich

__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html



More information about the Tutor mailing list