Question

In: Computer Science

Python This part involves creating a function that will manage a List of unique strings. The...

Python

This part involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back.

  1. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing.

  2. Create a test program that takes a string as input and then calls the function over and over until the user enters "Done." If the string "Done" is entered, the program sorts the list and prints it out line by line.

Solutions

Expert Solution

Python code:

#defining unique fnction
def unique(string,lst):
    #checking if strng is not in lst
    if(string not in lst):
        #adding string to lst
        lst.append(string)
    #returning lst
    return lst
#asking for string
string=input("Enter string: ")
#initializing lst
lst=[]
#looping till done is entered
while(string!="Done"):
    #calling unique function
    lst=unique(string,lst)
    #asking for string
    string=input("Enter string: ")
#printing the contents in sorted array
print(*sorted(lst),sep="\n")

Screenshot:


Input and Output:


Related Solutions

Design a function in python that takes a list of strings as an argument and determines...
Design a function in python that takes a list of strings as an argument and determines whether the strings in the list are getting decreasingly shorter from the front to the back of the list
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Using Python:     "We have a list of strings: \n",     "```python\n",     "CharList = ['a',...
Using Python:     "We have a list of strings: \n",     "```python\n",     "CharList = ['a', 'b', 'c', 'd']\n",     "```\n",     "Now, we write a program to delete some elements from the list. <br> \n",     "The indexes of the elements to be deleted are stored in IndexList <br>\n",     "\n",     "```Scenario-1```: IndexList = [3, 0]\n",     "```python\n",     "CharList = ['a', 'b', 'c', 'd']\n",     "IndexList = [3, 0]\n",     "for n in range(0, len(IndexList)):    \n",    ...
1. Implement the function calculate_score that consumes three parameters, two strings and a list. The strings...
1. Implement the function calculate_score that consumes three parameters, two strings and a list. The strings will each be ONE character and will represent a nucleotide. The list will be a nested int list representing a 4x4 score matrix. This function will return the value (int) from the nested int list at the location of the two referenced nucleotides. a. An example call to calculate_score would be calculate_score(“A”, “T”, score_matrix). If we look at the alignment score table in the...
Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to...
Creating a list/tuple in python 2. Using a list of lists containing X’s and O’s to represent a tic tac toe board, write code to check if the board has a winner.
Write a program that uses Python List of strings to hold the five student names, a...
Write a program that uses Python List of strings to hold the five student names, a Python List of five characters to hold the five students’ letter grades, and a Python List of four floats to hold each student’s set of test scores. The program should allow the user to enter each student’s name and his or her four test scores. It should then calculate and display each student’s average test score and a letter grade based on the average....
This function will be given a list of strings and a character. You must remove all...
This function will be given a list of strings and a character. You must remove all occurrences of the character from each string in the list. The function should return the list of strings with the character removed. Signature: public static ArrayList<String> removeChar(String pattern, ArrayList<String> list)
write a javascript function called cal_modes that will take a List of numbers or strings as...
write a javascript function called cal_modes that will take a List of numbers or strings as input and returns a List of the most frequent values. If there's only one most-frequent value, it returns a single-element List. example cal_modes([3,4,5,5]) should return [5] cal_modes([8.9, 1, 1]) should return [1] cal_modes([2.5, -2, -2, 2.5]) should return [2.5] cal_modes([3,3,4,4]) should return [3,4] cal_modes([3,4,5]) should return [3,4,5], because all occur with equal frequency cal_modes(["hi", "what", "where", "hi"]) should return ["hi”]
(PYTHON) Q2 Strings, a more complex program from requirements In part A you are asked to...
(PYTHON) Q2 Strings, a more complex program from requirements In part A you are asked to write the pseudocode for the program. In part B you are asked to write the syntax of the code for the program you outlined in the pseudocode. Q2 Part A - Pseduocode Create the Pseudocode for the program outlined in Q5. Make sure that your program includes all the requirements outlined. This cell is markdown, you do NOT need to use markdown to format...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT