in Education by
In a list with range(1,16) and I am trying to divide this list in some fixed numbe n . Let's assume n=7 >>> y [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,] >>> k = [ y [o:p + 7] for o in range(0, len(y), 7) ] >>> k [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15]] Now I want to split this list in such a manner that I get n chunks even/uneven, How can I do that? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
There are many methods to do it, but I'll suggest you to use more_itertools.divide Syntax: import more_itertools as mit iterable = range(1, 16) [list(c) for c in mit.divide(7, iterable)] Output: [[ 1, 2, 3, 4, 5, 6], [ 7, 8, 9, 10], [11, 12, 13, 14],

Related questions

0 votes
    How can I get the number of elements of a list? Ex- items = [] items.append("one") items.append("two") items.append("three") Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    How to remove an element from a list by index in Python, I tried list.remove method but it search the list and ... How can I do this? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I am confused about the usage of string.join(list) instead of list.join(string), for instance see this code: ... reason behind this? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    How can someone get a index (1) in Python for a list ["qwe", "asd", "zxc"] and an item "asd" in the list? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I want to write a program which returns different values for different input,it can be easily done using switch ... some alternative? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    How can I convert a str from uppercase, or half uppercase to lowercase? E.x. "Decimeter" to "decimeter" Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I am a learner and just want to know the basic concept of super(). Here in the given code I want to know ... () ChildOne() ChildTwo() Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I want to freeze the dos pop-up, I already tried raw-input as mentioned in my study material of Python 2.6 and ... (3**200) raw_input() Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I want to use python to connect to a MySQL database, how can I do that? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I want to extract an extension from a filename in Python, How can I do that? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    In Python, How to remove trailing and leading whitespace from str ? For instance check this: " Hey" --> "Hey" " ... "Harsh has a dog" Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Can someone tell me how to find all the files in directory with .txt extension in Python? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    How to check which Python version is interpreting my script? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Can someone tell me a python -m SimpleHTTPServer equivalent Python 3? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Can someone tell me how to refer a null object in Python? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
...