简体   繁体   中英

How to access distinct elements of a tuple inside an array, passed as function argument?

I am trying to manipulate distinct elementf of a tuple, which is part of an array.

What I have:

def my_function(lis):
  for i in lis:
    x[i], y[i], z[i] = lis[i]
  ...

As in the main I have:

my_function([(1,2,3), (4,5,6), (7,8,9), (10,11,12)]):
  ...

The result was:

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

As mentioned, I am trying to access distinc element of the tuple from the function and manipulate them.

Each i is a tuple; you probably want

for i in lis:
    x, y, z = i
    # use x, y, and z

or simply

for x, y, z in lis:
    # use x, y, and z

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM