+ 1
is there any alternative to using dictionaries in python
asking for anything else that can be used instead of dictionaries
6 Respuestas
+ 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")
+ 2
indexed how?
+ 2
having the same indexes?
+ 2
hmmm, thanks boss i see, its understandable now
+ 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
+ 1
jamil stark
Yes, having the same indexes.
I will post an example for you.
Give me a few minutes