working with dictionary or lists python -


i have following statement

onehot  = collection.defaultdict(list) 

that fill 2 dimentional vector. when print onehot here get:

print(onehot) --->defaultdict<class'list'>,{0:['1200',1],1:['1203',2],2:['1400',4]} 

which perfect . question is there way 'paired' value onehot . example:

onehot 1200 ---> 1  onehot 1800 ---> 32  

i'm newbie python i'm not sure it.

update problem don't know 1200 in list, want , i'm interested in number in 2nd dimension.
need the list 1200 , return values of 2nd dimension in case 1

here function returns second element in list , uses first element key (what want if understood correctly). can trivially extend produce new dict, use directly.

def getbyfirstlistelement(k):         ret = [] #there multiple hits, returns list of         key, value in onehot.enumerate():              if value[0] == k:                  ret.append(value[1])         return ret 

version returns dictionary:

def getpairdict(k):             ret = {}#there multiple hits, returns list of             key, value in onehot.enumerate():                  if value[0] == k:                      ret.update((value,))#add values dict             return ret 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -