I am working on a simple code and I want to automate the list element accessing process in python and store them in another variable. Here is my code:
>>>names = ['James', 'Tom', 'Mark', 'Tim']
>>>def name_create():
... number = len(names)
... for index in range(number):
... print("name"+str(index))
...
>>>name_create()
>>>name0
name1
name2
name3
Now I want to access all names automatically one by one and store them in the above output names. Like when I do print(name0)
, it'll show me the name stored inside it.
Example : >>>name0
>>>'James'
>>>name1
>>>'Tom'
How can I do this in python?