strings = [] #is empty, i.e. no elements, length is 0 n = eval(input("Enter the number of strings you have: ")) for i in range(n): #loop n times string = input("Enter a string: ") strings.append(string) #display as a list [v1,v2,...,vn] print(strings) print(type(strings)) print("Length of strings list:", len(strings)) #access each element using in operator. "traverse" the list for string in strings: print(string, end=" ") print() #use index to access each element for i in range(len(strings)): print(i, ":", strings[i]) #print(strings[5]) #functions that take array argument #print("Sum=",sum(strings)) #cannot do sum of strings print("Length=",len(strings)) print("Max=",max(strings)) print("Min=",min(strings)) #do something to each element, e.g. convert to uppercase for i in range(len(strings)): strings[i] = strings[i].upper() # print(i, ":", strings[i]) print(strings) #(repeatedly) search a list. There is no .find() method! item = input("Enter string to search for in the array: (-999 to quit) ") while item != "-999": if item in strings: print("Found it (first) at index:", strings.index(item)) #index: must exist! print("#times in the list:", strings.count(item)) #count: 0 OK else: print("not found") item = input("Enter string to search for in the array: (-999 to quit) ") #sort the list. Type of elements must be same. strings.sort() print(strings) #reverse the list (does not sort) strings.reverse() print(strings) #Deleting elements: # pop() deletes and returns the last element lastone = strings.pop() print(lastone) #list is one shorter print(strings, " Length:", len(strings)) # pop(index) deletes and returns the index_th element del_i = int(input("Enter the index of the element to remove from the list: ")) removed = strings.pop(del_i) print(removed) print(strings, " Length:", len(strings)) ''' 12 dog cat elephant camel ant zebra wolf raccoon chipmunk mouse whale hippotamus '''