if statement - Python Counter doesn't count -
import urllib2 f=urllib2.urlopen("http://www.mbnet.com.pl/dl.txt") list = range(1,50) counter={} lines in f: tab_lines=lines.split(" ") formated_tab=tab_lines[-1].strip().split(',') #print formated_tab in formated_tab: if in list: counter[i]+=1 print counter.items() my counter doesn't work , don't know why :( this list of lottery numbers. count how many times drawn each number. instead of using: counter[i] = counter.get(i, 0) + 1 you can try collections.defaultdict : counter = defaultdict(int) so final version should this: import urllib2 collections import defaultdict f=urllib2.urlopen("http://www.mbnet.com.pl/dl.txt") list = range(1,50) counter=defaultdict(int) # use defaultdict here lines in f: tab_lines=lines.split(" ") formated_tab=tab_lines[-1].strip().split(',') in formated_tab: if int(i) in list: counter[i] += 1 # do...