Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5834

Sort 2 lists get index values out

$
0
0

@mikhail wrote:

I am trying to make a function “sortListByClass” and just been stuck, like crazy. I’ve been writing and rewriting it forawrds and backwards with no luck.

def sortListByClass(listToSort, NumbersToSortBy):

I have a list that is structured in a specific way
NumbersToSortBy = [‘99’, ‘100’, ‘103’, ‘105’]
listToSort = [‘105’, ‘99’, ‘100’, ‘100’, ‘103’, ‘99’] it keeps going for a while
I need to feed both of them into the function and get index values out
something that would look like this
[1, 5, 2, 3, 4, 0]
I am then going to use this “matrix” to organize 3 other lists by, which I know how to do.

Somehow I am hitting a wall with this one.

After a lot of googling around, I found this

indices = [i for i, x in enumerate(my_list) if x == value]

And I cannot grasp how that is working when I feed it just one value, thus I cannot figure out how to deconstruct it and make it into a loop that works as a function.

Very new to python, any help is appreciated.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 5834

Latest Images

Trending Articles



Latest Images