Jump to content
UBot Underground

How to reverse a list?


Recommended Posts

Hey botters!

 

 

Here is a question i have been breaking my head over since the last couple of days.

 

As the title already stated, how can i reverse a list?

 

Say list a contains:

date 3

date 2

date 1

 

I want to get another list with:

date 1

date 2

date 3

 

Been looking all over the place but since the search function here kinda sucks and google didnt came up with a proper answer i ask this here on the forum.

 

Anyone? :P

Link to post
Share on other sites

I think this is the most elegant way (you only need one variable, which is a pointer to list position/integer):

clear list(%LIST)
add list to list(%LIST, $list from text("date 3
date 2
date 1", $new line), "Don\'t Delete", "Global")
set(#LIST ROW, $subtract($list total(%LIST), 1), "Global")
loop($list total(%LIST)) {
    add item to list(%LIST, $list item(%LIST, #LIST ROW), "Don\'t Delete", "Global")
    remove from list(%LIST, #LIST ROW)
    decrement(#LIST ROW)
}

Link to post
Share on other sites

The easiest method :

add list to list(%reversed_list, $sort list(%mylist, "Ascending"), "Delete", "Global")

where %mylist is your list with descending items.... but can be done in many,many ways....

Link to post
Share on other sites

The easiest method :

add list to list(%reversed_list, $sort list(%mylist, "Ascending"), "Delete", "Global")

where %mylist is your list with descending items.... but can be done in many,many ways....

This won't reverse the list, it will sort it.

Link to post
Share on other sites

Thanks all you guys for your ideas, awesome!

For some stupid reason it didnt work for me or just partial, with a few lines messed up in the reversed lists.

But i came up with a solution, done with the input from you guys ;)

 

set(#STATUS, $text from list($sort list(%STATUS, "Descending"), $new line), "Global")

 

This did the trick for me... :D

 

Thanks guys for all your input!

Link to post
Share on other sites

Yes,and sorting will reverse that list (particular case for the list given :) )

Ok, it will reverse this specific list, but I thought Walter is trying to use real dates inside list...if dates aren't sorted at start and aren't sortable format it won't work.

Link to post
Share on other sites
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...