Extracting lists in python script

Practicing with Python I ran into this little problem,
Could someone tell me why the code doesn’t work? and how can i solve it…
Thank you

You need to apply the reverse function to LIST 1. LIST 2 and LIST 3 are not lists, so the variables are unnecessary.

If you need a copy of the first list, I suggest you assign it to a new variable before using the sort() and reverse() functions, as they will manipulate the original list.

1 Like

If you put brackets around the OUT line>>

OUT = [NumerosDes,NumerosOrd,NumerosRev]

That will create a stacked list of those three values, each sublist being one of the three lists that you’ve created.

If you want to have it output just your List 3 (NumerosRev) then you can have the last line read:

OUT = NumerosRev

As @bayowindapo , mentions the reverse function doesn’t actually return a new list.

Alternative is to reverse it during sort with the reverse parameter.

1 Like

Thank you for your comments and the link… if I understood…
In order to obtain 3 different lists, I must create 2 additional functions that can do this process differently…???

What I was looking for as a result was to obtain 3 lists in the OUT
1.-Original list.
2.-Ordered List.
3.-Reverse List…
Could you show me how you could do it… I appreciate your comments… I’m in the learning process… thanks

I’ve already tried your suggestion and it hasn’t worked for me, it’s still getting errors.

I’ve tried to make a copy of the list without success…
The COPY TO() method… gives me an error why ???

Maybe try this?


Please tell me if there is any way to hold DesNumbers.sort() = in a separate variable… and the others in the same way… thanks

The REVERSE method should be applied to the list of ordered numbers.

Not at a CPUT to check, but the sort, reverse, and other various functions performed on lists in Python do not make new lists, but alter the existing list object. Some examples to show what I mean:

myList = [8,5,1,6]
OUT = myList

The result of the above code will be [8,5,1,6] in the Dynamo environment.

myList = [8,5,1,6]
OUT = myList

The result of that code should be [1,5,6,8]

myList = [8,5,1,6]
OUT = myList

The result of that should be [8,6,5,1].

If you need all three lists, you’d want to add a secondary action to build a subsequent variable, like so:

myList = [8,5,1,6]
baseList = [i for i in myList]
sorted = [i for i in myList]
reversed = [i for i in myList]
OUT = [baseList, sorted, reversed]

1.- Why do you place the BRACKETS and what does it mean.

2.-How to read the “i” before the for … I had only seen the for i in mylist … but I had never seen it before the for … Could you explain to us how the code and its logic would be read? …? Thank you

sort() and reverse() modify lists in place, this functions return nothing, you can’t assign this function to a variable with = operator.
you can use sorted() instead of