Reference error for zip() function

URL of experiment: FYP [PsychoPy]

Description of the problem:

I am getting a reference error, which I believe is from the " zip () " function not being available in JS. Does anyone know the equivalent code? I believe I may also run into an error shortly after as I have used the “cycle” and “shuffle” functions as well. They are all in one chunk of code which I have added below.

combinedList = list(zip(choiceImages, cycle(labelsWhole)))
combinedList = [list (elem) for elem in combinedList]

I have the code now set to “both” as I have had to remove the import settings for random and cycle.

Best wishes

Shuffle will automatically translate to util.shuffle in the code component. For zip and cycle, can you rewrite the Python with using simpler tools?

I’m still quite new to coding so I’m not sure what I’d be able to replace zip and cycle with.

The code pairs the choice images against set images (which is where the zip and cycle are coming in) so that this list can be shuffled and then separated to ensure the right pairings later.

Try this:

combinedList = []
for Idx in range(len(choiceImages)):

This should work locally and online (via the Auto translate). I’m not sure what combinedList = [list (elem) for elem in combinedList] is supposed to do, so I’ve left that bit out.

That’s got it!

I was working on something similar, though mine was using a lot of while loops and never quite worked.

I think the “elem” bit made it into a list of lists, which the code you’ve provided does much more easily.

I have ran into another error, so I will post that elsewhere.

Thanks again

1 Like

This solved a question I’ve been working to solve! But, is there a way to then split the combined list into two (a la List1, List2 = zip(*CombinedList))?

I use loops to split mine, there’s probably a more elegant way to do it but mine would look something like:

for i in CombinedList:

That works for me at least