How to reverse a list?

Hello,

how do i reverse a list ?

X = (IN[0]).reverse

OUT = X

i get no correct results

is it because of using sandbox?

KR

Andreas

It’s because your list is in a list. You have a list of a single item (list). That single item reversed is still that single item. There’s no need for brackets in your codeblock.

The syntax for reversing a list in python is myList.reverse().

2 Likes

@L2 on the list reverse node, or remove the [] from your code block.

You’ve made a list of lists (the … already forms a list, the [] isn’t required unless you want make sublists or change the level) so the list.reverse node is reversing your list of 1 items at L3 instead of your list of 26 items at L2

2 Likes

If you’re in Python, this a bit of a trick you can use with list slice syntax as well:

7 Likes

for info, the reverse method is an “in-place” method

6 Likes