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 7953679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:12:56+00:00 2026-06-04T03:12:56+00:00

Im trying to write a function that creates set of dynamic sublists each containing

  • 0

Im trying to write a function that creates set of dynamic sublists each containing 5 elements from a list passed to it.Here’s my attempt at the code

def sublists(seq):
    i=0
    x=[]
    while i<len(seq)-1:
        j=0
        while j<5:
            X.append(seq[i]) # How do I change X after it reaches size 5?
     #return set of sublists

EDIT:

Sample input: [1,2,3,4,5,6,7,8,9,10]

Expected output: [[1,2,3,4,5],[6,7,8,9,10]]

  • 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-06-04T03:12:58+00:00Added an answer on June 4, 2026 at 3:12 am

    Well, for starters, you’ll need to (or at least should) have two lists, a temporary one and a permanent one that you return (Also you will need to increase j and i or, more practically, use a for loop, but I assume you just forgot to post that).

    EDIT removed first code as the style given doesn’t match easily with the expected results, see other two possibilities.

    Or, more sensibly:

    def sublists(seq):
        x=[]
        for i in range(0,len(seq),5):
            x.append(seq[i:i+5])
        return x
    

    Or, more sensibly again, a simple list comprehension:

    def sublists(seq):
        return [seq[i:i+5] for i in range(0,len(seq),5)]
    

    When given the list:

    l = [1,2,3,4,5,6,7,8,9,10]
    

    They will return

    [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a function that will filter a list of tuples
I am trying to write a function that returns the index of the passed
I am trying write a function that generates simulated data but if the simulated
i am trying to write a function that will make DataRow[column] return nullable typed
I'm trying to write a function that will let me red-shift or blue-shift a
I am trying to write a function that includes a file named header.php in
I am trying to write a function that will: Disable the submit button when
I am trying to write a function that will randomly return an (x,y) co-ordinates
I'm trying to write a function that takes multiple arguments, which can come either
I'm trying to write a function that would use its first argument, then send

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.