list - why zip returns only two items (Python 3) -


i'm having problems understanding happens here.

networkfile="http://regulondb.ccg.unam.mx/menu/download/datasets/files/network_tf_gene.txt"  = 36  lista = []  n in range(0,8):      data = urllib.request.urlopen(networkfile).readlines()[i]     line = data.decode('utf-8')     line2 = line[0:5]     lista.append(line2)     = + 1  print(lista)  values = []  in range(0,8):      values.append('')  print(values)  d = dict(zip(lista,values))  print(d) 

i know far efficient way deal type of problem, i'm pretty new this'll have do.

my problem output looks like:

'accb\t', 'accb\t', 'acrr\t', 'acrr\t', 'acrr\t', 'acrr\t', 'acrr\t', 'acrr\t']  ['', '', '', '', '', '', '', '']  {'accb\t': '', 'acrr\t': ''} 

the first 2 lists work properly, implied print-command, zip 2 lists, , create dictionary of them, dictionary contains 2 elements each list, , have no idea why after i've tried find out hours.

any other tips & improvement suggestions appreciated well. thanks.

i suggest breaking code logical steps, rather doing multiple steps in same line. you'll see zip isn't giving 2 items, it's dict.

lista = ['accb\t', 'accb\t', 'acrr\t', 'acrr\t', 'acrr\t', 'acrr\t', 'acrr\t', 'acrr\t'] values = ['', '', '', '', '', '', '', ''] >>> list(zip(lista, values)) [('accb\t', ''), ('accb\t', ''), ('acrr\t', ''), ('acrr\t', ''), ('acrr\t', ''), ('acrr\t', ''), ('acrr\t', ''), ('acrr\t', '')] 

so see, you're getting values expected. when put dictionary, have many identical keys, overwritten. dictionary can gave 1 of each key.

>>> dict(_) {'acrr\t': '', 'accb\t': ''} 

'acrr\t' , 'accb\t' 2 keys, in dictionary, each show once.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -