Separate the two-air range by two vectors



  • A table is available in the form of a volume where the first index is my_array[i][0] received id, my_array[i][1] Second name. We need to split it into two separate sets: one with names, one with id. The decision that came into the head:

    id = []
    names = []
    for item in my_array:
        id.append(item[0])
        names.append(item[1])
    

    Is it possible to implement this more easily without a cycle all over the body?



  • If I understood the task correctly, for example:

    id, names = list(zip(*my_array))[:2]
    

    P.S.: If you're interested in productivity, you should pay attention. numpy etc.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2