Created
February 22, 2019 22:35
-
-
Save erickdsama/13ad8bb138c542f8bce5fbd2df5d4a7f to your computer and use it in GitHub Desktop.
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
with open('Downloads/problem_1_data.txt', 'r') as content_file: | |
import re | |
content = content_file.read() | |
data = [] | |
init = 0 | |
while True: | |
person = {} | |
person["name"] = content[init:init+10].strip() | |
person["middlename"] = content[init+10:init+20].strip() | |
init_street = init+50 | |
person["lastname"] = content[init+20:init_street].strip() | |
address_length = int(content[init_street:init_street+3]) # los primeros 3 digitos dicen cuanto mide la direccion | |
end_street = init_street + 3 + address_length # se toma la direccion despues de la longitud | |
person["address"] = content[init_street:end_street] | |
no_hobbies = content[end_street] # cuantos hobbies tengo es el primer digito | |
hobbie = "" | |
init_hobbies = end_street + 1 | |
end_hobbies = init_hobbies | |
for i in range(0, int(no_hobbies)): # se recorre para cada hobbie | |
end_hobbies = init_hobbies + 10 | |
hobbie += content[init_hobbies: end_hobbies] | |
init_hobbies = end_hobbies | |
init = end_hobbies # se agrega el final de "la linea" que es el inicio de la proxima | |
person["hobbie"] = hobbie | |
data.append(person) | |
if init >= len(content)-1: | |
break | |
import simplejson | |
print simplejson.dumps(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment