Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,884 questions

51,810 answers

573 users

How to use map() to call a function in for loop with Python

3 Answers

0 votes
def add(n):         
    return 10 + n
    
for i in map(add, range(7)):         
    print(i)
    

  
'''
run:

10
11
12
13
14
15
16

'''

 



answered May 21, 2019 by avibootz
edited May 21, 2019 by avibootz
0 votes
def mul(a, b):         
    print(a, b)
    return a * b
     
r1 = range(4)     
r2 = range(7)     
for i in map(mul, r1, r2):         
    print(i)
     
 
   
'''
run:
 
0 0
0
1 1
1
2 2
4
3 3
9

'''

 



answered May 21, 2019 by avibootz
edited May 21, 2019 by avibootz
0 votes
def mul(a, b):         
    print(a, b)
    return a * b
    
r1 = range(4)     
r2 = range(7, 10)     
for i in map(mul, r1, r2):         
    print(i)
    

  
'''
run:

0 7
0
1 8
8
2 9
18

'''

 



answered May 21, 2019 by avibootz

Related questions

...