Display a certain vector in a 2D list

Asked

Viewed 18 times

1

I have the following problem:

  • I have a 2D vector and wish to display only the first vector ([250, 27.65863337187866, 93.38094023943002, 27.65863337187866]).

  • I wrote a code, but it’s showing everything.

  • Below the code:


lista_1 = [[250, 27.65863337187866, 93.38094023943002, 27.65863337187866], [0, 392, 327, 30, 348, 12, 64, 324]]

for i in lista_1:
    print (i)

Where am I going wrong?

Grateful for the help.

1 answer

0


I may have misunderstood, but if you only want to access the first vector go to the index of that vector on the shortlist:

lista_1 = [[250, 27.65863337187866, 93.38094023943002, 27.65863337187866], [0, 392, 327, 30, 348, 12, 64, 324]]
print(lista[0]) #[250, 27.65863337187866, 93.38094023943002, 27.65863337187866]

In this case, it is the first internal vector, so it is in the index 0

When you do:

for i in lista_1:
    print (i)

You’re going through the entire list printing each internal vector around the loop, printing them all.

  • It’s true Miguel! I’m so tired of programming today, I forgot about it. But again I appreciate your help. A big hug.

  • You’re welcome to @Danilo, we’re here to learn. But you should go rest and be like this lol. Tomorrow you’ll have a fresh head

  • kkkk. It’s true. I’ll stop for today.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.