Hi all! I am new to python and coding in general. I am following along in a book and have come across code that the(interpreter/compiler **not sure which ones right) don't like. I am using VS Code in Anaconda to create and run the .py files. I don't know if that makes a difference. Anyways here is the code. Any help on understanding why this isn't working would be much appreciated. I think its the first line(def alphabetize(original_list=[])) it don't like. it has the squiggly line underneath it. I will be really thankful for any help/guidance anyone can give...
def alphabetize(original_list=[]): """Pass any list in square brackets, displays a string with items sorted""" #Inside the function make a working copy of the list passed in. sorted_list = original_list.copy() #Sort the working copy. sorted_list.sort() #Make a new empty string for output final_list = '' #Loop through sorted list and append name and comma and space. for name in sorted_list: final_list += name + ', ' #Knock of last comma space if final list is long enough final_list = final_list[:-2] #Return the alphabetized list. return final_list names = ['McMullen', 'Keaser', 'Maier', 'Wilson', 'Yudt', 'Gallagher', 'Jacobs'] alphabetize(names)
buran write May-08-2023, 09:28 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.