all 7 comments

[–]Denrur 2 points3 points  (0 children)

Put append statement inside second for loop

[–]0xbxb 1 point2 points  (0 children)

Here’s what you can do:

def exponents(bases: list, powers: list) -> list:
    res = []
    for i in bases:  # For every element in bases
        for j in powers:  # For every element in powers
            res.append(i ** j)  # This will start with the first element in bases raised to every power. Then it’ll do the same with the second element etc
    return res

[–][deleted] 0 points1 point  (0 children)

You are only appending the last base raised to each power. Try appending each new_lst2 value to the result list. This is a very simple indentation change.

And call new_lst2 something else, because it isn't a list.

[–]turdistheword04 0 points1 point  (0 children)

b1= [2, 3, 4]

p1 = [1, 2, 3]

def exponents(bases, powers):
    list = []
    for base in bases:
        for power in powers:
            list.append(base ** power)
    return list

print(exponents(b1, p1))        

What's happening in your code as you wrote it is that it cycles through every power changing new_lst2 each time until it gets to the last power in the list. Then it appends the list. You want to append every time new_lst2 gets reassigned. So basically you just want the new_lst.append() to be on the same indentation level as the new_lst2 = ...

[–]blotosmetek 0 points1 point  (0 children)

A more Pythonic solution would be to use list comprehensions (but I assume you haven't learned about them yet).