python - Working with enumerate -


so i've started python last few days nothing basic coding knowledge 5 years ago. i'm in love.

i'm importing .csv contains historical alliances sorted dyad...so each alliance has special number. there many more in file same country. i'm trying have user give country , date , able return countries in alliance year. here's 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 dyad num, country code , country, country code , country, day of alliance beginning, month, year, day of end, month, year. last parts aren't important.

import csv name='united kingdom' diad = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] open('list.csv') inputfile:     r = list(csv.reader(inputfile))     i, j in enumerate(r):          if j == name:               diad[0]=name           print "true"               diad.insert(0, name) 

i run , nothing, if statement isn't true... don't understand how though. you're looking @ first 2 lines of data, shouldn't enumerate find instance of "united kingdom" , insert found diad list? if can make piece work task should easy.

iterating through csv iterates through rows, not columns. in each iteration, j list of columns. you'd need iterate through elements in j well, in order compare against string.

i think you're confused enumerate does. don't need here @ all, in fact. give index along value of thing you're enumerating. in case, you'd on first iteration 0 plus first row, 1 second row, , on. since you're not using index, don't want use enumerate.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -