Discuss Scratch

newer12
Scratcher
13 posts

sorting word alphabetical

Hoe do sort out numbers alphabetically?
deck26
Scratcher
1000+ posts

sorting word alphabetical

Can you show what you mean with an example?

If you mean something like sorting the word versions so 5,6 7 would sort as five, seven, six it could be a lot of work.
newer12
Scratcher
13 posts

sorting word alphabetical

8,1,2,55 would be 55,8,2,1 or if z,d,a would sort as a,d,z
Yllie
Scratcher
100+ posts

sorting word alphabetical

You can use the fact that B > A and ABC > AAA in the same way as 2 > 1 and 123 > 111.
Insert your words or numbers into a list:

addApeto WordsaddBirdtoWords addWolftoWords addButterflytoWords addDolphintoWords addMousetoWords

Then use the script shown bellow.
Note that the words/numbers in the list “Words” will be sorted to another list called “Sorted Words”.

Hope this helps!

deleteAllof Sorted WordsrepeatuntillengthofSorted Words=lengthofWordssetCounterto0setHighestto repeatlengthofWordschangeCounterby1ifitemCounterof Words>HighestandnotSorted WordscontainsitemCounterof WordsthensetHighesttoitemCounterof WordsaddHighesttoSorted Words


The “Sorted Words” list will now include all words in “Words” in the order: Ape, Bird, Butterfly, Dolphin, Mouse, Wolf

Last edited by Yllie (March 28, 2015 08:21:16)

deck26
Scratcher
1000+ posts

sorting word alphabetical

One of those is ascending order, the other descending - are you sure that's what you want?

I'm finished for today but if you search for sorting projects you should find something. You may need to treat numbers separately from text, especially if sorting in reverse order for one compared with the other.
newer12
Scratcher
13 posts

sorting word alphabetical

Thanks
gtoal
Scratcher
1000+ posts

sorting word alphabetical

deck26 wrote:

One of those is ascending order, the other descending - are you sure that's what you want?

I'm finished for today but if you search for sorting projects you should find something. You may need to treat numbers separately from text, especially if sorting in reverse order for one compared with the other.

Take your pick - most of these should work on strings as well as numbers. HOWEVER if your inputs are all numbers, Scratch may treat them as numerical rather than string data, so a hack to avoid that would be to put a single character (eg “A”) in front of every item using the ‘join’ operator, and then remove it afterwards. Whether the same hack would work with a space character I'm not sure.

https://scratch.mit.edu/studios/880696/

Last edited by gtoal (March 30, 2015 12:07:39)

deck26
Scratcher
1000+ posts

sorting word alphabetical

Whatever you do you need to check that it matches what you're after. If you have three numbers, eg 13, 85 and 112 how do they get sorted? If you just precede each with an alpha character I'm guessing the sort would give you the order A112, A13, A85 which is obviously not a numerical sort - you'd need leading zeroes to sort the numbers properly.

There's nothing there that can't be resolved but care is required.

Powered by DjangoBB