Home > other >  How to find unique identifier of a list within a tuple?
How to find unique identifier of a list within a tuple?

Time:09-27

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]?

CodePudding user response:

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]
>>> 
  • Related