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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:22:20+00:00 2026-06-07T12:22:20+00:00

I have looked around but have been unable to find out why my code

  • 0

I have looked around but have been unable to find out why my code is failing, and how to do it right. I’m new (3 days) to coding, so forgive my noobishness.

I start with a list of integers, and essentially I want to make a new or updated list where the new list’s first index has a value = the sum of the first 10 values of the original list (0-10), and then the new list’s second index has a value = the sum of the original list’s (1-11) index values.

The problem is that it adds everything incorrectly, and in a manner such that I have not yet been able to figure out the pattern.

Here’s what I have:

def sum_range(filename, grouping = 10):
    """sums up the ss values for 'groupings' numbers of indices.
    Shows ALL results, regardless of how high or low strandedness is"""

    sslist = ssc_only(filename)
    # "ssc_only(filename)" takes my input and returns it as a list of int,
    # which I want to use for this function

    sslist = [sum(sslist[i:i+grouping]) for i in sslist]

    return sslist
  • 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-07T12:22:22+00:00Added an answer on June 7, 2026 at 12:22 pm

    I think you probably want for i in range(len(sslist)) (use xrange instead of range in python 2 if you’re concerned about memory consumption).

    lstlen=len(sslist)
    sslist = [sum(sslist[i:min(i+grouping,lstlen)]) for i in range(lstlen)]
    

    You are looping over list items instead of over list indices

    Of course, your last 10 elements will be the sum of less than 10 elements. As I don’t know what you want to do with those elements, I’ll leave it to you to figure out what you want to do with them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked around, but I have been unable to figure this out, some
I have looked around the internet but haven't been able to find a working
I've looked around and have been able to find a piece of code that
I've looked around but have yet to find a great solution the the following
Ok, I have looked around on SO and haven't been able to find an
I looked around but haven't found an answer to this. I have a CentOS
I have looked around here and the Internet in general but it seems this
Sorry if this is obvious but have looked around and can't get this working:
I've got zero experience with Python. I have looked around some tutorial materials, but
I've looked around and have bits and pieces but can't put the puzzle together.

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.