def input_list_of_strings(): '''Prompts the user for a list of strings. Returns a list of the strings. For example, given input "['hello','there','bear']" return ['hello','there','bear'] ''' lst = input("Enter a list of strings ") # Suppose lst is '["hello","there","brown","bear"]' lst = lst.split(',') # Now lst is ['["hello"', '"there"', '"brown"','"bear"]'] # lst[0] is '["hello"' # lst[1] is '"there"' # lst[2] is '"brown"' # lst[3] is '"bear"]' # # The first and the last elements of the list need to be handled # as special cases # first = lst[0][2:-1] last = lst[-1][1:-2] # Initialize a new list to return new = [] # Now, process all the elements between the first and the last for element in lst[1:-1]: # We don't want the extra quotes around the string new.append(element[1:-1]) new.insert(0,first) new.append(last) return new def main(): print(input_list_of_strings()) main()