# Wakefield's Daily Tips

**URL:** <https://discourse.psychopy.org/t/wakefields-daily-tips/43371>\
**Category:** Blog\
**Tags:** online, pavlovia\
**Created:** [January 1, 2025, 3:36pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371 "2025-01-01T15:36:55Z")\
**Posts on this page:** 1\
**Showing post:** 70

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 10, 2025, 4:57pm UTC](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/70 "2025-03-10T16:57:47Z")

</div>

## Extending lists

In Python you can extend lists using the addition sign or the extend function.

```auto
a = [1, 2]
b = [3, 4]
a = a + b
print('a1', a)
a.extend(b)
print('a2', a)
b = b.extend(b)
print('b1', b)

```

**Output**  
a1 [1, 2, 3, 4]  
a2 [1, 2, 3, 4, 3, 4]  
b1 None

For PsychoJS this code is auto translated to:

```auto
a = [1, 2];
b = [3, 4];
a = (a + b);
console.log("a1", a);
a.concat(b);
console.log("a2", a);
b = b.concat(b);
console.log("b1", b);

```

**Output**  
a1 1,23,4  
a2 1,23,4  
b1 [3, 4, 3, 4]

Two things are going wrong here.

1. a + b is concatenating the two lists as strings.
2. a.concat(b); doesn’t alter list a

As per [Wakefield's Daily Tips - #27 by wakecarter](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/27), here is a custom function for joining two lists.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/5/f5225e5b23fad363b1fccf46e7a74ab903af6e30.png)

**Python**

```auto
def concat(a, b):
    return a + b

```

**JavaScript**

```auto
function concat(a, b) {
    return a.concat(b);
}

```

Then in your code component, write `c = concat(a, b)` instead of `c = a + b`.

This could be exended to three (or more) lists using a+b+c+etc. and a.concat(b, c, etc.) in the function. If would also be possible to set up a more complex function which checks the number of arguments, but unless you are regularly concatenating a chain of lists, it would probably be easier to just call the simple function more than once.

> [@Select subset of stimuli – nothing is displayed](https://discourse.psychopy.org/t/select-subset-of-stimuli-nothing-is-displayed/29301):
>
> URL of experiment: [Sign in · GitLab](https://gitlab.pavlovia.org/inga.lueck/fadeoutdt2_livk-mi) Description of the problem: I try to create individual stimulus lists for each participant. There are four different stimulus categories and all stimuli of each category should be divided into biased (14 items/category) and unbiased (3 items/category) sets. Begin experiment – Python exp\_block = 0 myTrialCounter\_baseline\_size = -1 # create list with all stimuli all\_la\_stim = ['Stimuli/bear.jpg', 'Stimuli/dog.jpg', 'Stimuli/donkey.jpg', 'Stimuli/elephant.jpg…

---

_[View the full topic](https://discourse.psychopy.org/t/wakefields-daily-tips/43371)._
