0

I want to store two parameter of a single user in single array. One is user money that he want to save and the time when he saves his money so this two parameter should be store in array how is it possible. I also want to grab them from the array like when i grab index 0 than it suppose to return me 2 things one the amount he saved and the time when he saved that amount. I am trying with the following code.

user_money_to_save =[100,399,4499]
time_save = [0.1,0.2,3.4]
user_data=[user_money_to_save,time_save]

print(user_data[0])#this is returning me user_money_to_save. not [100,0.1] 
Ahmed Yasin
  • 886
  • 1
  • 7
  • 31

1 Answers1

0

You can use zip() function which takes iterables (can be zero or more), aggregates them in a tuple, and return it.

user_money_to_save =[100,399,4499]
time_save = [0.1,0.2,3.4]

user_data = list(zip(user_money_to_save, time_save))

print(user_data)

Output

[(100, 0.1), (399, 0.2), (4499,3.4)]

ParthS007
  • 2,581
  • 1
  • 22
  • 37