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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:06:27+00:00 2026-06-02T19:06:27+00:00

I have got a list containing nested lists like this : [ [datetime.datetime(2000, 12,

  • 0

I have got a list containing nested lists like this :

[ [datetime.datetime(2000, 12, 10, 0, 0), 0.0011] , [datetime.datetime(2000, 12, 11, 0, 0), 0.0013 , [datetime.datetime(2000, 12, 12, 0, 0), 0.0014]]

etc..

How do I go about adding sub elements 2 by 2 like this :

sum(0.0011,0.0013) + 0.0014

then taking the result of this sum and adding it to the next sub element ?

I`m basically trying to compound the values .

thanks!

  • 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-02T19:06:28+00:00Added an answer on June 2, 2026 at 7:06 pm

    The easiest way to do this is with the sum() builtin and a generator expression:

    >>>items = [[datetime.datetime(2000, 12, 10, 0, 0), 0.0011], [datetime.datetime(2000, 12, 11, 0, 0), 0.0013 ], [datetime.datetime(2000, 12, 12, 0, 0), 0.0014]]
    >>>sum(item[1] for item in items)
    0.0038000000000000004
    

    Edit:

    If you want to print out the result of each stage of the summation, you want to use functools.reduce() (which, in 2.x is the reduce builtin).

    from functools import reduce
    import datetime
    
    items = [[datetime.datetime(2000, 12, 10, 0, 0), 0.0011], [datetime.datetime(2000, 12, 11, 0, 0), 0.0013 ], [datetime.datetime(2000, 12, 12, 0, 0), 0.0014]]
    
    def add_printing_result(a, b):
        total = a+b
        print(total)
        return total
    
    reduce(add_printing_result, (item[1] for item in items))
    

    Which gives us:

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

Sidebar

Related Questions

I have this but I got an error: -- test if a list contains
I have 2 Lists containing lottery-ticket instances. One List holds tickets that won a
I have got a mysql table containing data about companies: id, company name, city,
I've got a many-to-many association between Lists and ListItems: a List knows about its
In the project I'm working on I have got a list List<Item> with objects
What I want to do is add and remove list items. I have got
Got a List of ClientContacts --- which have EITHER a LastName (in the case
I've got a list of links which have a click event attached to them,
you have some info on an item and you got a list of comment
I have a list of places in listview which i got from parsing JSON.

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.