0

If I have a list with 600,000 elements

The list I have is quite complicated, and has nothing to do with sequence or order, but let's use this one with 600,000 elements as an example:

main_list = list(range(0,1200000,2)

and if I want to to create a list that slices the main_list into a new list likes this:

sub_list =  [main_list[0:100], main_list[100:200], main_list[200:300], main_list[300:400], ...]

How can I do it?

james_24
  • 99
  • 8
  • 4
    Something like `sub_list = [main_list[x:x+100] for x in range(0, len(main_list), 100)]` or am I misunderstanding what you're trying to do? – Joachim Isaksson Mar 11 '20 at 05:42
  • What does "*has nothing to do with the sequence or order*" mean? You want to split the main list into smaller sub-lists with random elements from the main list? random buckets? random number of sub-lists? Post an expected output that matches the description, because the previous comment does match the new list sample. – Gino Mempin Mar 11 '20 at 05:58
  • @JoachimIsaksson thanks this is what I'm looking for. – james_24 Mar 11 '20 at 06:01
  • @GinoMempin I have a list with random number, so I use the list in the question as an easy example for asking. Thanks for asking – james_24 Mar 11 '20 at 06:06

0 Answers0