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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:52:58+00:00 2026-05-23T13:52:58+00:00

I´m new in python and I´m trying to find the best way to approach

  • 0

I´m new in python and I´m trying to find the best way to approach this problem , I need to understand if this can be made only with loops and functions (whithout lists comprehensions).
I also need to find the more elegant way to solve this kind or problems,
simple functions? recursivity? lists comprehensions? Generator functions? At the end of this text is my attempt. Thank you.

I have this lists:

base=[1,2]

alist=[1,2,3]

blist=[3,2,1]

and i need to find this for each “time step” :

result(j)=base(j-1)+alist(j)-blist(j)

this is result I need to find:

[1+1-3 2+1-3]

[1+1-3+2-2 2+1-3+2-2] 

[1+1-3+2-2+3-1 2+1-3+2-2+3-1]

This is my attempt: It doesn´t work because at each iteration I have to consider the previous value of base. I have tried…

def calc(base,alist,blist):
    lineNum=0
    while lineNum < 3:
        result=[]
        for i in range(len(base)):
           result.append(base[i]+alist[lineNum]-blist[lineNum]) 
        print To
        lineNum+=1
  • 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-23T13:52:59+00:00Added an answer on May 23, 2026 at 1:52 pm

    Try the following:

    def calc(base, alist, blist):
        for num in range(1, 4):
            result = []
            for b in base:
                result.append(b + sum(alist[:num]) - sum(blist[:num]))
            print result
    

    Here is the result with the data you gave:

    >>> calc(base, alist, blist)
    [-1, 0]
    [-1, 0]
    [1, 2]
    

    Alternatively, you can do this without the sum() call by keeping the previous result and just adding/subtracting the next value from alist and blist, which may be more efficient:

    def calc(base, alist, blist):
        result = base[:]
        for num in range(3):
            for i, v in enumerate(result):
                result[i] = v + alist[num] - blist[num]
            print result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to python (and this site); I am trying to write a
I am very new to python. I need to draw this shape for college
I'm writing Python 3 extensions in C++ and I'm trying to find a way
I am a RoR programmer new to Python. I am trying to find the
Im new two python and am trying to grow a dictionary of dictionaries. I
I'm brand new at Python and I'm trying to write an extension to an
I'm new to python but I've run into a hitch when trying to implement
I am pretty new to python and working with firmata I am trying to
I'm really new to Python. I'm trying to import a third party module called
I'm new to python, and I'm trying to get to know the list comprehensions

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.