Python, Replace function?

What would the body be if I was to make a function that is designed to modify lst so that its element at pos is replaced with item. Without built-in functions

For example: def replace(lst, pos, item):

>>> mylist = [1,2,3]

>>> replace(mylist, 2, 'a')

>>> mylist

[1, 2, 'a']

I'm just curious

1 Answer

Relevance
  • Robert
    Lv 6
    7 years ago
    Favourite answer

    Try (with blanks instead of the dots):

    def replace(lst, pos, item):

    ... lst[pos] = item

    ... return lst

Still have questions? Get answers by asking now.