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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,637 questions

56,925 answers

573 users

How to create a list from two lists (list comprehension, like nested for loops) in Python

2 Answers

0 votes
lst1 = [5, 7, 8, 1, 0]
lst2 = [8, 9]

lst3 = [x * y for x in lst1 for y in lst2]

print(lst3)

 
     
 
'''
run:
 
[40, 45, 56, 63, 64, 72, 8, 9, 0, 0]
 
'''

 



answered Jan 11, 2021 by avibootz
0 votes
lst1 = [5, 7, 8, 1, 0]
lst2 = [8, 9]

lst3 = []

for x in lst1:
    for y in lst2:
        lst3.append(x * y)

print(lst3)

 
     
 
'''
run:
 
[40, 45, 56, 63, 64, 72, 8, 9, 0, 0]
 
'''

 



answered Jan 11, 2021 by avibootz

Related questions

1 answer 261 views
1 answer 307 views
2 answers 276 views
2 answers 364 views
364 views asked May 8, 2017 by avibootz
1 answer 282 views
...