r/pythonhelp • • Aug 02 '20

Title.fuction? HELP PLEASE

Post image
3 Upvotes

19 comments sorted by

View all comments

2

u/wentaas Aug 02 '20

if you want to get every element in the list to be title, you need a for loop

musicTitles = [] # create an empty list we’ll populate it under for str in music: # takes every element in music so str is first “kay”, then “em” and so on musicTitle = str.title() # gets for example Kay musicTitles.append(musicTitle) # adds it to the list which we’ll use

print(musicTitles)

2

u/wentaas Aug 02 '20

another way to do it is to replace the list itself

i = 0 # this will be our index for str in music: # same thing as above music[i] = str.title() # music[0] = str.title() would replace the first element with the title i += 1 # and i will be first 0 then 1 and so on for every element

print(music)

2

u/wentaas Aug 02 '20

for printing lists beautifully you could print inside that loop so for str in music: str = str.title() print(str)

or print(*musicTitles) would print like Kay Em etc print(*musicTitles, sep=“, “) would do Kay, Em etc you can replace sep with whatever you like

2

u/TheDevine13 Aug 02 '20

Thank you!