Skip to content

Instantly share code, notes, and snippets.

@aniversarioperu
Created July 19, 2014 21:27
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 aniversarioperu/c201e79b62f84a6b6cfd to your computer and use it in GitHub Desktop.
Save aniversarioperu/c201e79b62f84a6b6cfd to your computer and use it in GitHub Desktop.
Compara los DNI de candidatos en archivos diferentes. Si los DNI son idénticos, extrae la organización política de un archivo y lo pasa al otro.
#-*- coding: utf-8 -*-
import codecs
import sys
# file that needs org politica
input_file = "hojas_3_4"
# file 0 as reference
ref_file = "hoja.tsv.0"
org_politicas = []
for i in codecs.open(ref_file, "r", "utf-8").readlines():
i = i.strip().split("\t")
obj = {i[0]: i[2]}
org_politicas.append(obj)
for i in codecs.open(input_file, "r", "utf-8").readlines():
out = ""
line = i.strip().split("\t")
dni = line[0]
found = "false"
for j in org_politicas:
if dni == j.keys()[0]:
out = j.values()[0] + "\t" + i.strip()
print out.encode("utf-8")
found = "true"
break
# this is the header row
if found == "false":
out = "ORGANIZACION POLITICA" + "\t" + i.strip()
print out.encode("utf-8")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment