简体   繁体   中英

How to find unique identifier of a list within a tuple?

I have a tuple which looks as below:

x = (2, 3, 4, [34, 45, 89])

I can find unique identifier of x using id(x)

How can I find the unique identifier of the list object [34, 45, 89] ?

Use map to map the id function (identifier function) for each value in the list:

>>> list(map(id, x))
[140725109860176, 140725109860208, 140725109860240, 1366170771648]
>>> 

Or a list comprehension:

>>> [id(i) for i in x]
[140725109860176, 140725109860208, 140725109860240, 1366170771648]
>>> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM