So I've just started with python the last few days with nothing but some basic coding knowledge from 5 years ago. I'm in love.
I'm importing a .csv which contains historical alliances sorted by dyad...so each alliance has a special number. There are many more in the file with the same country. I'm trying to have a user give a country and a date and be able to return the countries they were in alliance with that year. Here's a row of data.
6 200 United Kingdom 255 Germany 1 1 1816 31 10 1822 1 0 1 0 0 1 0
6 200 United Kingdom 300 Austria-Hungary 1 1 1816 31 10 1822 1 0 1 0 0 1 0
First number is the dyad num, then country code and country, country code and country, day of alliance beginning, month, year, day of end, month, year. Last parts aren't really important.
import csv
name='United Kingdom'
diad = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
with open('list.csv') as inputfile:
r = list(csv.reader(inputfile))
for i, j in enumerate(r):
if j == name:
diad[0]=name
print "true"
diad.insert(0, name)
I run it and get nothing, so the if statement isn't true... I don't understand how though. You're looking at the first two lines of data, shouldn't enumerate find any instance of "United Kingdom" and insert what it found into the diad list? If I can make this piece work my task should be easy.