Question

I am trying to write a python function called legion that takes a list B and...

I am trying to write a python function called legion that takes a list B and returns the indeces of all values in B that are greater than zero. So far I have

def legion(B):

for i in range(len(B)):

if (B[ i ]>0):

But am not sure if this is right or what to do next. For example if I have legion([3,3,4,0,0,8,2,0,0,5]) it should return ([0,1,2,5,6,9]) as these are in the indeces of the numbers in list B that are greater than 0.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def legion(B):
new_lst=[]
for i in range(len(B)):
if (B[i]>0):
new_lst.append(i)
return new_lst
  
list=legion([3,3,4,0,0,8,2,0,0,5])
print(list)

Add a comment
Know the answer?
Add Answer to:
I am trying to write a python function called legion that takes a list B and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT