Python Challenge level 2: “ocr”
Hint 1: recognize the characters. maybe they are in the book, but MAYBE they are in the page source.
Hint 2: find rare characters in the mess below (this hint is found looking at the source, and I stored it in file 02.txt for convinience). Looking for clues in whatever information you get will become a must from now on. By rare I understand ‘few appearences’, not neccesarily strange characters:
mess = open("02.txt").read()
dict = {}
for ch in mess:
dict[ch] = dict.get(ch, 0) + 1
print "".join(ch for ch in mess if dict[ch] == 1)
taher@borg:~/src/python_challenge$ python 02.py equality
Well. Up to Level 3.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
I’ve done it in another way ;)
src = string.printable[62:] des = ' ' * len(src) t = string.maketrans(src,des) print (mess.translate(t)).replace(' ','')And another way to do it is:
mess = open('mess.txt', 'r').read() for ch in string.punctuation: try: mess = mess.replace(ch, '') finally: mess = mess.replace('\n', '') print mess[...] cause insanity in laboratory mice « Python Challenge level 0: “warming up!” Python Challenge level 2: “ocr” [...]
I did this:
[code]
ocrText = open("files\\level2.txt").read()
result = ''
for i in ocrText:
if i.isalpha():
result += i
print result
[/code]
Awesome!
import string
mess = open("02.txt").read()
result=""
for ch in mess:
if ch in string.letters:
result+=ch
print result
re.sub(“[^A-Za-z]“, “”, open(“ocr.txt”).read())
@kelownagurl A couple of users (early Twitter adopters) encountered such an error. Basically the API call hangs instead of returning data.
Hey guys, i used this:
mess = open("02.txt").read()
chars = " "
for i in range(len(mess)):
if mess[i] not in chars:
chars = chars + mess[i]
print chars
Then i had this output:
%$@_^#)&!+]*}[({equality