How to implement key of key in python?

Andrea D'Amore anddamNOALPASTICCIODICARNE+gruppi at brapi.net
Sat May 10 03:07:10 EDT 2014


On 2014-05-10 03:28:29 +0000, eckhleung at gmail.com said:

> While it is fine for a small dataset, I need a more generic way to do so.

I don't get how the dataset size affects the generality of the solution here.

>From your first message:

> attr = {}
> with open('test.txt','rb') as tsvin:
>     tsvin = csv.reader(tsvin, delimiter='\t')
>     for row in tsvin:
>         ID = row[1]

so your is solved by adding a simple
  attr[ID] = {}

after the ID assignment. It seems simple to implement and generic enough to me.


> unfortunately none of them illustrates how to store the values and 
> access them later.

You access the stored value by using the variable name that holds it, 
but here you should probabily make more clear what your actual issue is.


> Moreover, they bring some new terms, e.g. combined, [], etc.

The "[]" syntax is used in Python for lists.

The term "combined" hasn't a specific pythonic meaning there and is 
just used as a meaningful variable name as the author is combining, 
i.e. adding, numerical values.


-- 
Andrea




More information about the Python-list mailing list