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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:47:45+00:00 2026-06-18T07:47:45+00:00

def run(first, second): sum=[] for i in range(len(first)): third.append(second[i]+first[i]) return sum print run([1,2,3],[10,20,30]) The

  • 0
def run(first, second):
    sum=[]
    for i in range(len(first)):
        third.append(second[i]+first[i])
    return sum

print run([1,2,3],[10,20,30])

The code works fine and prints out a list with three elements where each element is the sum of the two elements of the same index in “second” and “first”, specifically [11, 22, 33]. Is there a more straightforward approach to return the same result?

  • 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-18T07:47:46+00:00Added an answer on June 18, 2026 at 7:47 am

    Sure, use the zip() built-in function and a list comprehension:

    def run(first, second):
        return [a + b for a, b in zip(first, second)]
    

    Demo:

    >>> def run(first, second):
    ...     return [a + b for a, b in zip(first, second)]
    ... 
    >>> print run([1,2,3],[10,20,30])
    [11, 22, 33]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import math def p(n): return 393000*((288200/393000)^n * math.exp(-(288200/393000)))/math.factorial(n) print p(3) When I run it,
@with_checker([int]) def check_sort(list_of_ints): self.assertTrue(isinstance(list_of_ints, list)) self.assertTrue(len(list) == len(qsort(list))) self.assertTrue(False) I'm trying to run this,
import bottle from bottle import route, run @route('/', method='GET') def homepage(): return {'foo' :
def download_if_dne(href, filename): if os.path.isfile(filename): # print 'already downloaded:', href return False else: if
I have 3 threads, that are currently running simultaneously. def f1(): print running first
Within my code, I use task.LoopingCall() to run some deferred function every second. I
In the following code, the first test passes, and the second one does not,
I have the following code: def steps(low, hi, n): rn = range(n) newrn =
The typical Python threadpool will have a structure like this one: def run(self): while
Use case: class MyTask(Task): queue = 'default_queue' def run(self): # do work Normally I

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.