Question

Need to do in Python? Can do in Javascript but not in Python Write a function...

Need to do in Python? Can do in Javascript but not in Python

Write a function named "indexed_list" that takes a list as a parameter. Your function should create a new array. Update the newly created list so that it has the same number of entries as the function's input. Assign each entry in the list you created the value of it's index. So the entry at index 0 would have the value 0, the entry at index 1 would be assigned the value 1, and so on. The function should return your new list.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def indexed_list(lst):
    result = []
    for i in range(len(lst)):
        result.append(i)
    return result


# testing the function here. Ignore it if not required. 
print(indexed_list([3, 0, 1, 8, 2]))
print(indexed_list([3, 9]))
print(indexed_list([]))

Add a comment
Know the answer?
Add Answer to:
Need to do in Python? Can do in Javascript but not in Python Write a function...
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
ADVERTISEMENT