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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:13:29+00:00 2026-05-29T08:13:29+00:00

For learning purposes, I’m trying to make a function using Python that takes in

  • 0

For learning purposes, I’m trying to make a function using Python that takes in another function and two arrays as parameters and calls the function parameter on each index of each array parameter. So this should call add on a1[0] & a2[0], a1[1] & a2[1], etc. But all I’m getting back is a generator object. What’s wrong?

def add(a,b):
    yield a + b


def generator(add,a1,a2):
    for i in range(len(a1)):
        yield add(a1[i],a2[i])


g = generator(add,a1,a2)

print g.next()

I’ve also tried replacing what I have for yield above with

yield map(add,a1[i],a2[i])

But that works even less. I get this:

TypeError: argument 2 to map() must support iteration

  • 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-29T08:13:30+00:00Added an answer on May 29, 2026 at 8:13 am

    Your definition of add() is at least strange (I’m leaning twoards calling it “wrong”). You should return the result, not yield it:

    def add(a, b):
        return a + b
    

    Now, your generator() will work, though

    map(add, a1, a2)
    

    is an easier and faster way to do (almost) the same thing. (If you want an iterator rather than a list, use itertools.imap() instead of map().)

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

Sidebar

Related Questions

I'm trying to build a safari extenstion (mostly for learning purposes) that creates a
I've Been Trying To Make A 3d renderer software (just trying for learning purposes)
Scenario: Creating an app for learning purposes and am trying to make it database
I'm currently trying to write a website for testing / learning purposes that will
I'm trying to write something very similar to an IM client (for learning purposes
I have a phpBB forum on my localhost for learning purposes..now I'm trying to
I'm trying to write a very simple cms (for learning purposes) in kohana 3
I'm new to Objective-c. For learning purposes I'm trying to build something like a
For learning purposes I created a toy project using grails. In this project I
For learning purposes, I'm looking for open source Rails projects that exemplify idiomatic usage

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.