[PyAR2] Mini Programming Challenge

Jesse Jaggars jhjaggars at gmail.com
Thu Oct 16 23:22:37 CEST 2008

I probably went a little overboard with the comprehensions, but they
are just so groovy.

def count_letters(s):
    l_dict = {}
    for c in [ch.lower() for ch in filter(lambda x: x.isalpha(), s)]:
        l_dict.setdefault(c, []).append(c)
    return dict((ch, len(count)) for ch, count in l_dict.iteritems())

if __name__ == "__main__":
    import pprint
            count_letters(raw_input("Enter a string of characters: ")))

More information about the PyAR2 mailing list