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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:58:36+00:00 2026-06-10T11:58:36+00:00

Hello I am using something the Grouper function from python’s itertools to cut large

  • 0

Hello I am using something the Grouper function from python’s itertools to cut large chunks of select where in(idlist) queries down for sqlite performance. The problem is grouper fills in the whole space of the chunksize even if the list is much smaller so I had to add a loop and comparison before which now I want to optimize.

# input list shorter than grouper chunk size
input = (1,2,3,4,5)

grouper(10,input)
# desired output = (1,2,3,4,5)
# actual output = (1,2,3,4,5,None,None,None,None,None)

# current fix for this issue
list_chunks = tuple(tuple(n for n in t if n) for t in grouper(10, input))

I think there has to be a way to do this without this loop and comparison.

Note: using python 2.5

  • 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-10T11:58:38+00:00Added an answer on June 10, 2026 at 11:58 am

    Something like this?

    >>> filter(bool, (1,2,3,4,5,None,None,None,None,None))
    (1, 2, 3, 4, 5)
    

    For more complicated case (eg, with 0 in list or you need to drop something differ from None) you can implement own lambda:

    >>> filter(lambda n: n is not None, (0,1,2,3,4,5,None,None,None,None,None))
    (0, 1, 2, 3, 4, 5)
    

    Or even

    >>> from functools import partial
    >>> from operator import ne
    >>> filter(partial(ne, None), (0,1,2,3,4,5,None,None,None,None,None))
    (0, 1, 2, 3, 4, 5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello i am using this Page.ClientScript.RegisterStartupScript() to call a javascript function from vb code
How to correctly do something like the following without using jQuery. $(document).ready(function(){ $(#someButton).click(function(){ alert(Hello);
Hello I am trying to call a method (fileReader) that is using openFileInput(filename) from
From what I understand using something like require_once will essentially copy and paste the
I wanted to print something using printf() function in C, without including stdio.h, so
Hello I need help with validation using regular expressions in javascript I need something
I'm using this pattern: http://localhost:8983/solr/select/?q=hello&wt=json&json.wrf=?&indent=true&hl=true&hl.fl=title It returns like: ?({ response:{numFound:100,start:0,docs:[ { id:1234, title:Something Hello
How to write a simple bittorrent application. Something like a hello world using a
Hello I want to make something like smoke simulator using iPhone mic. What is
How would I print Hello every nth of an iteration in ruby using something

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.