Skip to content

Commit ed8c3ca

Browse files
committed
Finally rewrote the code for Python3!
1 parent 4449f0b commit ed8c3ca

File tree

47 files changed

+70
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+70
-115
lines changed

01-good-old-times/tf-01.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env python
2-
3-
from __future__ import print_function
42
import sys, os, string
53

64
# Utility for handling the intermediate 'secondary memory'

02-go-forth/forth.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Author: Chris Meyers @
55
# http://openbookproject.net/py4fun/forth/forth.html
66
#
7-
from __future__ import print_function
87
import re
98

109
try:

02-go-forth/tf-02.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
from __future__ import print_function
32
import sys, re, operator, string
43

54
#
@@ -92,7 +91,7 @@ def frequencies():
9291

9392
def sort():
9493
# Not in style, left as exercise
95-
stack.extend(sorted(stack.pop().iteritems(), key=operator.itemgetter(1)))
94+
stack.extend(sorted(stack.pop().items(), key=operator.itemgetter(1)))
9695

9796
# The main function
9897
#

03-monolith/tf-03.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env python
2-
3-
from __future__ import print_function
42
import sys, string
53
# the global list of [word, frequency] pairs
64
word_freqs = []

04-cookbook/tf-04.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
from __future__ import print_function
32
import sys, string
43

54
# The shared mutable data

05-pipeline/tf-05.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
from __future__ import print_function
32
import sys, re, operator, string
43

54
#
@@ -59,7 +58,7 @@ def sort(word_freq):
5958
and returns a list of pairs where the entries are
6059
sorted by frequency
6160
"""
62-
return sorted(word_freq.iteritems(), key=operator.itemgetter(1), reverse=True)
61+
return sorted(word_freq.items(), key=operator.itemgetter(1), reverse=True)
6362

6463
def print_all(word_freqs):
6564
"""

06-code-golf/tf-06-1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
from __future__ import print_function
32
import re, string, sys
43

54
stops = set(open("../stop_words.txt").read().split(",") + list(string.ascii_lowercase))

06-code-golf/tf-06-bm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
from __future__ import print_function
21
from functools import reduce
3-
print (reduce(lambda string, tup: string + tup[0] + ' - ' + str(tup[1]) + '\n', sorted( filter(lambda tup: tup[0] not in open(__import__('os').path.join(__import__('os').path.dirname(__file__), '..', 'stop_words.txt')).read().lower().split(','), reduce(lambda word_dict, word: word_dict if (word_dict.__setitem__(word, word_dict.get(word, 0) + 1) if True else None) else word_dict, filter(lambda word: len(word) > 1, (''.join(map(lambda letter: ' ' if ord(letter) not in set(range(ord('a'), ord('z') + 1)) else letter, open(__import__('sys').argv[1]).read().lower()))).split()), {}).iteritems()), key=lambda tup: tup[1], reverse=True)[0:25], '')) # hole in one?
2+
print (reduce(lambda string, tup: string + tup[0] + ' - ' + str(tup[1]) + '\n', sorted( filter(lambda tup: tup[0] not in open(__import__('os').path.join(__import__('os').path.dirname(__file__), '..', 'stop_words.txt')).read().lower().split(','), reduce(lambda word_dict, word: word_dict if (word_dict.__setitem__(word, word_dict.get(word, 0) + 1) if True else None) else word_dict, filter(lambda word: len(word) > 1, (''.join(map(lambda letter: ' ' if ord(letter) not in set(range(ord('a'), ord('z') + 1)) else letter, open(__import__('sys').argv[1]).read().lower()))).split()), {}).items()), key=lambda tup: tup[1], reverse=True)[0:25], '')) # hole in one?

06-code-golf/tf-06-pn.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python
22
# My golf score is slightly lower!
33
# Best wishes, Peter Norvig
4-
5-
from __future__ import print_function
64
import re, sys, collections
75

86
stopwords = set(open('../stop_words.txt').read().split(','))

06-code-golf/tf-06.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
from __future__ import print_function
32
import heapq, re, sys
43

54
words = re.findall("[a-z]{2,}", open(sys.argv[1]).read().lower())

0 commit comments

Comments
 (0)