-1

I'm learning python and I've come across this problem that seems very simple, but I can't find a way

I have two lists:

animals = ['cat', 'dog']
animals_name = ['rex', 'laika']

I tried:

for animal in animals:
    for name in enumerate(animals_name):
        print(animal, name)

and got:

cat (0, 'rex')
cat (1, 'laika')
dog (0, 'rex')
dog (1, 'laika')

I was hoping to get:

cat rex
dog laika
Alec
  • 8,529
  • 8
  • 37
  • 63
Cris
  • 15
  • 2

2 Answers2

1

Use the zip() function:

list(zip(animals, animals_name))
Alec
  • 8,529
  • 8
  • 37
  • 63
0
animals = ['cat', 'dog']
animals_name = ['rex', 'laika']


for index, value in enumerate(animals):
    print(animals[index], animals_name[index], sep=' ')

output

cat rex
dog laika
sahasrara62
  • 10,069
  • 3
  • 29
  • 44