Reputation: 171
I have the following code:
for {for loop assertion }:
if (a) > 0 and b > 0:
print('same')
elif (a) < 0 and b < 0:
print('same')
else:
print('different')
This produces a list like this:
different
different
same
different
same
different
same
different
different
same
different
different
different
different
different
same
What I want to do is save this to another variable. Could you please advise how I can accomplish that?
Upvotes: 0
Views: 151
Reputation: 359
Try this, it should work, if not tell me why:
lst = []
for {for loop assertion }:
if (a) > 0 and b > 0:
lst += ["same"]
if (a) < 0 and b < 0:
lst += ["same"]
else:
lst += ["different"]
or you could do:
lst = []
for {for loop assertion }:
if (a) > 0 and b > 0:
lst.append("same")
if (a) < 0 and b < 0:
lst.append("same")
else:
lst.append("different")
Upvotes: 3