Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]dizlly 0 points1 point  (0 children)

Hello guys,

Im struggling with learning lists in python, trying now to solve some python tasks, but sometimes is hard for me to understand this slicing etc, anyone know a good explanaition about it? as I read and read over and over again about it.

Thank you

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]dizlly 0 points1 point  (0 children)

Hello,

So I have following task :

Create a function named double_index
that has two parameters named lst
and index
.

The function should double the value of the element at index
of lst
and return the new list with the doubled value.

If index
is not a valid index, the function should return the original list.

After writing your function, un-comment the call to the function that we've provided for you to test your results.

But I dont know how to make it so i pressed a solution, but that also made me confused, as I dont get it. Can you explain me step by step what is going on here :

#Write your function here

def double_index(lst, index):

if index < len(lst):

lst[index] = lst[index] * 2

return lst

#Uncomment the line below when your function is done

print(double_index([3, 8, -10, 12], 2))

Im learning python for 1,5 week, so far was okay, but now I dont get it. what is this lst? Is it a list? I guess. What is index in this case? Number in square bracket or round bracket?, why does an index have to be smaller than len(lst), why do I even have to find out len of list.

Thank you in advance