pythonlistpathgrasshopper

Add str to end of each number in a list


This is the what I have right now:

L1 = range(0,3,1)
num = str(L1)
L2 = ';1'
path = [i + ";1" for i in num]
print(path)

which gives me this:

['[;1', '0;1', ',;1', ' ;1', '1;1', ',;1', ' ;1', '2;1', '];1']

but I want it to look like this:

0;1
1;1
2;1

The goal is to use this in a grasshopper script to create new paths that can replace existing paths.


Solution

  • The problem is that num = str(L1) will convert the entire L1 list into a string but you only want to convert the elements of L1 list into string.

    Try this:

    path = [str(i) + ";1" for i in range(0,3,1)]
    for line in path:
        print(line)
    

    Output:

    0;1
    1;1
    2;1