How to get sublist by condition

I have a list, how to get new_list based on length of new list.
I don’t want use ‘if’ because len(list) is verylong
Thank Advance!


list = [1,2,3,4,5,6,7,8,9,10]
len(list) = 10
count = Variable (count<len(list))

count = 0

new_list = [1]

count = 2

new_list = [1,10]

count = 3

new_list = [1,5,10]

count = 5

new_list = [1,3,5,7,9]

count = 10

new_list = list #1,2,3,4,5,6,7,8,9,10
# so on count = ...

Hola Amigo @manhgt214 buenas! Interensting question, is this wath you are looking for??


I think i got it, hope that works!




1 Like

We need more information. Are those randomized values from the list or do they follow a pattern? Do they have to be sorted? If it is a pattern it looks like it includes some rounding. How does the rounding work?

1 Like

Hi!! Thank you

But if K =4 is new_list[1] = 4.333, newlist[2] = 7.666 but two number dont have in list.
I want get new_list from list but not creat new item.

1 Like

Thank you very much!!
This is I need. Earn it!

Always a pleasure Amigo, good exercise by the way but you didn’t answer Nick’s question I remain the doubt whether the script can be used?

1 Like

I have a list color, based on number of elements I wanna get random new_list color but keep range of index. I think solved it. Thank you!!

1 Like