Skip to content

Instantly share code, notes, and snippets.

@xavortm

xavortm/ch03.py Secret

Created August 29, 2015 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xavortm/e51f1f9423f42f6291c7 to your computer and use it in GitHub Desktop.
Save xavortm/e51f1f9423f42f6291c7 to your computer and use it in GitHub Desktop.
# challenge 3
# http://www.pythonchallenge.com/
# -----------------------------------------------------------------------------
# Large letters - from 65 to 90
# Small letters - from 97 to 122
def filter_list(map, original) :
i_line = 0
for line in map :
if line.find('100010001') > 0 :
print original[i_line][line.find('100010001') + 4],
i_line += 1
def convert_list(source) :
# iterators
i_line = 0
i_char = 0
# Swap area for list changes
new_line = []
new_source = []
for line in source :
# Check if the curent symbol is big letter
# if 65 <= ord(c) <= 90 :
# if 91 <= ord(c) <= 122 :
new_line = list(line)
for char in line :
if 65 <= ord(char) <= 90 :
new_line[i_char] = '0'
if 91 <= ord(char) <= 122 :
new_line[i_char] = '1'
i_char = i_char + 1
# Remove the new line symbol
new_line.pop()
# this will be the returned value
new_source.append(''.join(new_line))
# Modify counters
i_line = i_line + 1
i_char = 0
return new_source
with open('text.txt') as f:
content = f.readlines()
new_content = convert_list(content)
filter_list(new_content, content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment