# How to connect lists together

**URL:** <https://forum.dynamobim.com/t/how-to-connect-lists-together/31969>\
**Category:** Developers\
**Created:** [February 11, 2019, 8:26pm UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969 "2019-02-11T20:26:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [February 11, 2019, 8:26pm UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/1 "2019-02-11T20:26:52Z")

</div>

hello guys ,  
i have many lists in my python script , and i made for loop to search for a number , if the number is not in the first list , i move to next list , and so on , but the problem is how to connect all lists together in an order to search in them sequentially

---

<div class="post-metadata">

**Author:** ![3Pinter](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/3pinter/32/74327_2.png) [@3Pinter](https://forum.dynamobim.com/u/3Pinter)\
**Post date:** [February 12, 2019, 12:31pm UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/2 "2019-02-12T12:31:42Z")

</div>

what do you what to know?

Which list the number is in? Which index?

1. create a list of all the lists you want to check
2. list.AllIndicesOf @L2

?

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/7/571e99d23eb8a11fb790dae81a816ae7d10a965b.png)

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [February 12, 2019, 7:04pm UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/3 "2019-02-12T19:04:26Z")

</div>

if i have three lists  
first = [1,3,6]  
second = [8,10,12]  
third = [14,16,18]  
and i have two numbers so if the first number = 1 it will check in the first list if the second number is less than any number in the list , if not it moves to the next list , so if i have two numbers (1, 15) the first number is 1 so it will search in the first list then the second and the third list will be the true one , finally if the condition is true in the first list it will print “first” if in the second list it prints “second” and so on , so in this example it will print “three”

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [February 13, 2019, 1:27am UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/4 "2019-02-13T01:27:15Z")

</div>

This is pretty confusing. Can you show it in a graph with what the inputs would be (the first, second, third list structure) and what you want the output to be?

---

<div class="post-metadata">

**Author:** ![stillgotme](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@stillgotme](https://forum.dynamobim.com/u/stillgotme)\
**Post date:** [February 13, 2019, 2:53am UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/5 "2019-02-13T02:53:12Z")

</div>

![test](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/3/c3a13e933a3735c7aab61ff606043098378f40be.png)

something like this?

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [February 13, 2019, 8:44am UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/6 "2019-02-13T08:44:32Z")

</div>

Iam sorry , what i want to do is complicated , but in a simple way ,i want a way to make an array of arrays like if i have three lists

first = [1,3,6]  
second = [8,10,12]  
third = [14,16,18]

Is there a way to make array of all this arrays like  
All = [first , second , third]  
So by make that “All[0]” i can access the elements of the first list

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [February 13, 2019, 8:51am UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/7 "2019-02-13T08:51:38Z")

</div>

So you mean the basic List.Create node?

 ![alistwtf](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/8/88608686673a24c9b53d80298d311047a984b6ee.png)

Please show your Dynamo graph, as it will be easier for us to understand you after seeing what your work/outputs are like.

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [February 13, 2019, 8:54am UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/8 "2019-02-13T08:54:52Z")

</div>

Yes , exactly but if there is a way to do that inside a python “text” scripting it will be better

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [February 13, 2019, 8:55am UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/9 "2019-02-13T08:55:39Z")

</div>

Can you show the python then? It should be simple with the .append() method but I would need to see what your inputs/variables look like.

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [February 13, 2019, 9:47am UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/10 "2019-02-13T09:47:46Z")

</div>

Joining the lists directly in Python is actually worse in regards to managing your graph. If you use the List.Create node like Kenny showed, it would allow you to access all of your lists (regardless of how many there are) through a single node. If you have all of your lists as separate inputs in Python, you would have to open your script every time you change the number of lists. Here’s an example using the Python node where all inputs are lists:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/2/c29246b8724e0c48fd6db86bd9baa500f031caa5.png)

The above option is only viable if all of your inputs are the lists you want to test.

Here is a modified strategy which will only work if all of the inputs after a specified index are lists:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/e/5ec85460b3f3707c8d629491e5a123d34cf80ab4.png)

Again, these are options if you want to do it in _Python_, but I would highly recommend using Kenny’s method instead.

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [February 13, 2019, 1:57pm UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/11 "2019-02-13T13:57:00Z")

</div>

I dont have to go in my python script every time , i can make a number node as input to the python script and i want to go deep into programming and i want to turn it to add-in in the future  
So simply , what i want to do that i have 3 fixed (unchangable) lists and one variable input(that input i type it manually) i want to search the input(a number ) through the lists (test if the number is equal to any number in the list) it will search the lists in an order and i want to make different outputs based on the list i found the number in it ( if i found the condition is true in the first list the ouput will be 20(for example ) ,if it in the second list the output will be 50) and so on

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [February 13, 2019, 9:08pm UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/12 "2019-02-13T21:08:16Z")

</div>

This is slightly different from the scenario you described earlier in the thread. Here is an example addressing one of the earlier posts:

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/3/83f6390a99738f8501c662bc2fa87dacf0548d44.png)

```
values_a = IN[0]
values_b_all = IN[1:4]
values_b_names = ['First', 'Second', 'Third']

results = []
for i in range(len(values_a)):
    value_a = values_a[i]
    for j in range(len(values_b_all)): # Assume same length for values_b_names as values_b_all
        values_b_name = values_b_names[j]
        values_b = values_b_all[j]
        if value_a in values_b:
            results.append(values_b_name)

OUT = results

```

[List Test.dyn](https://forum.dynamobim.com/uploads/short-url/AfAg5qHSfXCwQisTwTmqbtdVJmZ.dyn) (11.2 KB)

You could modify this to instead output the numbers which were matched. For example:

```
if value_a in values_b:
    results.append(value_a)
```

---

<div class="post-metadata">

**Author:** ![kennyb6](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kennyb6](https://forum.dynamobim.com/u/kennyb6)\
**Post date:** [February 14, 2019, 1:26am UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/13 "2019-02-14T01:26:19Z")

</div>

Like I asked in my first post, please show a Dynamo graph detailing what you want the inputs to be and what you want the expected output to be. It would help more than just having a text-based description.

cgartland’s script should work. If you want the output to stop after it finds the item in one of the lists (for example, value of 1 is in first and third, but only output first), this can work:

```
# The inputs to this node will be stored as a list in the IN variables.
testing = IN[0]
checkvals = IN[1:4]
checknames = ["first", "second", "third"]

outvals = []

# Place your code below this line
for val in testing:
    for i, check in enumerate(checkvals):
        if val in check:
            outvals.append(checknames[i])
            break

# Assign your output to the OUT variable.
OUT = outvals

```

 ![pythoncheckmultiplelists](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/a/baed9f870495cf37b6296b9235208459da1ceffa.png)

What do you want it to show if it cannot find the value in any of the lists?

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [February 15, 2019, 8:34am UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/14 "2019-02-15T08:34:06Z")

</div>

Now that’s working

---

<div class="post-metadata">

**Author:** ![eng.elfeky](https://avatars.discourse-cdn.com/v4/letter/e/f475e1/32.png) [@eng.elfeky](https://forum.dynamobim.com/u/eng.elfeky)\
**Post date:** [February 15, 2019, 8:36am UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/15 "2019-02-15T08:36:18Z")

</div>

I want to throw an exception if the input is out of a specific range

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [February 19, 2019, 6:15pm UTC](https://forum.dynamobim.com/t/how-to-connect-lists-together/31969/16 "2019-02-19T18:15:48Z")

</div>

You can just use `raise Exception('Your Error Message Here')` to raise a custom exception. You can also create a custom `Exception` class so that you can track different types of exceptions more easily. For example:

```
class InvalidInputError(Exception):
    pass

user_values = [1, 2, 8]
valid_range = range(5)

for user_value in user_values:
    if user_value not in valid_range:
        raise InvalidInputError('User-defined value is outside of valid range')

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/4/b4c483f440734c6dfd586b44938757666d32faad.png)

[List Test.dyn](https://forum.dynamobim.com/uploads/short-url/3kCdih8xy4c1olKFEbUbnHPmXRZ.dyn) (11.3 KB)

Note that the above example will only work with integers, but can be easily modified to handle floats as well.
