0
list1=['name1','name2','name3']
list2=[123,1234,12345]

I wanna say in python, if index of 'name1' in the first list is equal to index of 123 in the second list without knowing them.

For example 'name1' and 123 is user input.

I have tried many things like using .index, but I get an error.

TypeError: list indices must be integers or slices, not str

and tried many other things but none worked as i wanted

2 Answers 2

2

You can do the following:

list1 = ['name1', 'name2', 'name3']
list2 = [123, 1234, 12345]

name = input("name: ")
num = int(input("num: "))  # don't forget to convert to int

if (name, num) in zip(list1, list2):
    print("Yay")
else:
    print("Aww")
Sign up to request clarification or add additional context in comments.

Comments

0

Assuming they are the same length

for count, data in enumerate(list1):
    if(list1[count] == list2[count]):
        print("yay")

If you just want to know if both lists contain the same data

for count, data in enumerate(list1):
    if(data in list2):
        print("yay")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.