From your question, I understand that you actually have three lists, weight
, age
and marks
, and have built a "table" with all the records with zip(weight, age, marks)
.
Now, you want to get the hash of each "row". If you want to use Python built-in hash
function, these rows must be immutable; tuples are immutable, lists are not (if you don't know the difference between tuples and lists, look here). That's no problem, because with zip
each created "row" is actually a tuple. So, to obtain the hash of each row, you may just use the map
function:
hashes = map(hash, list1)
Now you have the hash of each row in hashes (note that you could replace hash
with any custom hash function with a tuple argument, if you want). Now you have all the hashes of your rows in hashes
, so hashes[23]
is the hash of the row list1[23]
, for example. If you want to have everything in a single structure, just zip
it again:
list1_and_hashes = zip(list1, hashes)
Note that each element of list1_and_hashes
is a tuple with two elements: first, the row itself (which is in turn a tuple with its corresponding weight, age and marks), and second, the hash of the row. If you want a table where every element has four fields (weight, age, marks and hash), you could use map
again with a lambda function.
list1_and_hashes_2 = map(lambda row_hash: list(row_hash[0]) + list(row_hash[1]),
list1_and_hashes)
Then you will have in list1_and_hashes_2
the table with four fields in each row.
PD: I'm assuming you are using Python 2. In Python 3, zip
and map
do not return lists, but generators; in that case, you may need to wrap some of your calls with list(...)
to obtain the actual structure.