Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3356986
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:34:47+00:00 2026-05-18T02:34:47+00:00

Given ( any ) list of words lst I should divide it into 10

  • 0

Given (any) list of words lst I should divide it into 10 equal parts.

x = len(lst)/10

how to give these parts variable names?

In the output I need 10 variables (part1, part2... part10) with x number of words in it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:34:47+00:00Added an answer on May 18, 2026 at 2:34 am

    One-liner returning a list of lists, given a list and the chunk size:

    >>> lol = lambda lst, sz: [lst[i:i+sz] for i in range(0, len(lst), sz)]
    

    Testing:

    >>> x = range(20, 36)
    >>> print x
    [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]
    
    >>> lol(x, 4)
    [[20, 21, 22, 23], 
     [24, 25, 26, 27], 
     [28, 29, 30, 31], 
     [32, 33, 34, 35]]
    
    >>> lol(x, 7)
    [[20, 21, 22, 23, 24, 25, 26], 
     [27, 28, 29, 30, 31, 32, 33], 
     [34, 35]]
    

    Update:

    I think the question is really asking is a function which, given a list and a number, returns a list containing $(number) lists, with the items of the original list evenly distributed. So your example of lol(x, 7) should really return [[20,21,22], [23,24,25], [26,27], [28,29], [30,31], [32,33], [34,35]]. – markrian

    Well, in this case, you can try:

    def slice_list(input, size):
        input_size = len(input)
        slice_size = input_size / size
        remain = input_size % size
        result = []
        iterator = iter(input)
        for i in range(size):
            result.append([])
            for j in range(slice_size):
                result[i].append(iterator.next())
            if remain:
                result[i].append(iterator.next())
                remain -= 1
        return result
    

    I’m sure this can be improved but I’m feeling lazy. 🙂

    >>> slice_list(x, 7)
    [[20, 21, 22], [23, 24, 25], 
     [26, 27], [28, 29], 
     [30, 31], [32, 33], 
     [34, 35]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to get a list of thread handles at any given time
Given a list A = [1 2 3 4 5 6] Is there any
Given a list of assorted length words, what is the best way to find
I have a static 'large' list of words, about 300-500 words, called 'list1' given
Simple question, given a list like this Clear[a, b, c, d, e, f]; lst
I'm trying to wrap words and words sequence from a given list with preg_replace.
I have a program which searches for words in a given list(alphabetically arranged). Thing
given any number, what's the best way to determine it is even? how many
Given any iterable, for example: ABCDEF Treating it almost like a numeral system as
Given any two sequences/vectors of M real numbers, I can easily compute their closeness

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.