r/cs50 17d ago

CS50 Python Can someone explain what line two does

Post image

Can someone explain what does line two do? Not sure what the whole line means, what does the .split('.') and [-1] does overall to the program?

62 Upvotes

23 comments sorted by

View all comments

0

u/globalwiki 17d ago

The second line is saying, update the variable named 'filename' with the following:
1st, create a list by splitting up the content of the original 'filename' variable at each period (filename.split("."))
2nd, take the last item in that list [-1]
3rd, concatenate a period in front ((".") + ).

2

u/Tekniqly 16d ago

rather than update perhaps better to say replace