Randomising conditions with alternating order in PsychoPy
Question: I have a simple experiment with 8 different trials that I wish to present only
once without repeat; participants are asked to 'solve' a numeric sequence
where 4 sequences have a solution (S) and 4 are unsolvable (U).

Thus, I have 8 trials:

S1, S2, S3, S4, U1, U2, U3, U4.

I want to present the trials so that they alternate:

S1, U1, S2, U2, S3, U3, S4, U4

However, I want to randomise the order of S and U, whilst maintaining the
alternating pattern.

For example, S3, U2, S2, U4, S4, U1, S1, U3

I am using the builder and am new to Python (although I am familiar with
coding in Matlab). The only solutions I can come up with is to try and shuffle
the order of the trials in the excel file and then combining them so they
alternate - this doesn't seems very elegant though.

Is there a simple way to implement this within the builder or by adding a code
component?

I have included the input file / excel table that defines the trials. The
column 'difficulty' indicates whether they are Solvable or Unsolvable trials.

cheers, Harry

[input](http://i.stack.imgur.com/PULwp.png)


Answer: Uses prior answer [on list
conversions](http://stackoverflow.com/questions/12355442/converting-a-list-of-
tuples-into-a-simple-flat-list) and concept of [list
comprehensions](http://www.secnetix.de/olli/Python/list_comprehensions.hawk)

    
    
    import random as r 
    a = ["s1","s2","s3","s4"]
    b = ["u1","u2","u3","u4"]
    r.shuffle(a)
    r.shuffle(b)
    trialList = [tr for pr in zip(a,b) for tr in pr]
    

