is there any alternative to using dictionaries in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

is there any alternative to using dictionaries in python

asking for anything else that can be used instead of dictionaries

26th Sep 2021, 4:07 AM
Jamil 🇺🇬 stark
Jamil 🇺🇬 stark - avatar
6 Answers
+ 2
jamil stark Example attached person = input() or "Amy" names = ["Bob","Amy","Zac"] ages = [21,34,14] for i in range(len(names)): if person == names[i]: print(person,"is",ages[i],"years old")
26th Sep 2021, 4:33 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
indexed how?
26th Sep 2021, 4:18 AM
Jamil 🇺🇬 stark
Jamil 🇺🇬 stark - avatar
+ 2
having the same indexes?
26th Sep 2021, 4:18 AM
Jamil 🇺🇬 stark
Jamil 🇺🇬 stark - avatar
+ 2
hmmm, thanks boss i see, its understandable now
26th Sep 2021, 4:36 AM
Jamil 🇺🇬 stark
Jamil 🇺🇬 stark - avatar
+ 1
You could set up 2 lists with the items of the lists indexed so they cross-reference each other. Then you could iterate through one list looking for a match, which would return the indexed item from the 2nd list. Dictionaries are much more efficient
26th Sep 2021, 4:13 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
jamil stark Yes, having the same indexes. I will post an example for you. Give me a few minutes
26th Sep 2021, 4:24 AM
Rik Wittkopp
Rik Wittkopp - avatar