Added style #2

This commit is contained in:
Crista Lopes
2013-09-22 08:51:35 -07:00
parent 27a419e6d2
commit 3468b95a94
4 changed files with 21 additions and 2 deletions

View File

@@ -1,11 +1,12 @@
Style #1 Monolithic
Style #1
==============================
Constraints:
- No abstractions
Alternative names of this style:
Possible names:
- Monolith
- Labyrinth
- Brain dump

11
02-code-golf/README.md Normal file
View File

@@ -0,0 +1,11 @@
Style #2
==============================
Constraints:
- As few lines of code as possible
Possible names:
- Code golf
- Try hard

7
02-code-golf/tf-02.py Normal file
View File

@@ -0,0 +1,7 @@
import re, string, sys
stops = set(open("../stop_words.txt").read().split(",") + list(string.ascii_lowercase))
words = [x.lower() for x in re.split("[^a-zA-Z]+", open(sys.argv[1]).read()) if len(x) > 0 and x.lower() not in stops]
unique_words = list(set(words))
unique_words.sort(lambda x, y: cmp(words.count(y), words.count(x)))
print "\n".join(["%s - %s" % (x, words.count(x)) for x in unique_words[:25]])