0
def get_name(list):
  ??

li=[1]
get_name(li) # -> 'li' simple string, 'li'
f'{get_name(li)}' # -> 'li' not [1]

I think it is very simple question. but I can't solve. Actually, value of list is not necessary. desired input li (not 'li') , desired output 'li' (not li)

younghyun
  • 341
  • 1
  • 8
  • No. Objects in Python do not know their own names, because they might have many names. Perhaps what you want is a dictionary, where YOU control mapping names to objects. – Tim Roberts Mar 16 '23 at 06:39
  • @TimRoberts umm.. okay! I'm making another function, I need this logic in the middle of the original function. If so, I'll have to think of a different way. Thanks!!! – younghyun Mar 16 '23 at 06:41
  • 1
    The need to know that is a red flag there is something wrong with your original function logic. Note that actually there may be objects never bound to a name, e.g. elements in a list created by comprehension. – buran Mar 16 '23 at 06:52

0 Answers0