How can I run through three separate arrays in the same for loop?

前端 未结 6 1312
遇见更好的自我
遇见更好的自我 2020-12-06 13:38

I have three arrays I am trying to run through and I want to use the values from all three arrays in one function. This might sound confusing but here is what I have:

<
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 14:20

    Here is a solution using zip with 3 arrays (test they are indeed the same length):

    for (name, (age, gender)) in zip(names, zip(ages, genders)) {
        makeUser(name, userAge: age, userGender: gender)
    }
    

    But maybe the cleanest of them all is just old fashioned C-style:

    for i in 0..

提交回复
热议问题