Created
April 23, 2014 15:11
-
-
Save un33k/11219266 to your computer and use it in GitHub Desktop.
Given a list of words, count the occurrence of each group of characters in any order that they might appear. Example: foo, ofo, oof are all counting towards foo = 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
words = """ | |
is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum | |
is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum | |
""" | |
counter = {} | |
import pdb; pdb.set_trace() | |
for w in words.replace('.', ' ').replace(',', ' ').split(' '): | |
word = w.strip() | |
if len(word): | |
key = ''.join(sorted(word)).lower() | |
record = counter.get(key, None) | |
if record is None: | |
record = [word, 1] | |
else: | |
record = [word, record[1]+1] | |
counter[key] = record | |
for c in counter: | |
print counter[c] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment