Question: PYTHON: 1. Write a function that takes in a list data structure as input. The function should create a new list and only include unique

PYTHON:
1. Write a function that takes in a list data structure as input. The function should create a new list and only include unique elements of the inputted list. Under the function, write code that calls the function with a test list like so and print out the result. Remember that your code should work for all lists of integers, not just the sample test here.
my_list = [1, 2, 3, 2, 1, 4] unique_list = get_unique_list(my_list) print(unique_list)
 PYTHON: 1. Write a function that takes in a list data
2. Write a function that takes in two dict data structures as input. Both dicts map str->int (the keys are strings and the values are integers). The function should compute a new dict which combines the two dicts by summing the values for the common keys. Keys that are not common should be left out. Use the following code to test your function, but remember that your function should for all str->int dict inputs, not just the test here.
my_dict_1 = {'a': 5, 'b': 12, 'c': 3, 'd': 9} my_dict_2 = {'b': 4, 'c': 9, 'd': 10, 'e': 16} combined_dict = get_combined_dict(my_dict_1, my_dict_2) print(combined_dict)
 
structure as input. The function should create a new list and only
3. Take in a string from the user and pass it as input to a function. Have the function return a dict which keeps count of each letter (in lowercase) in the string, excluding spaces. Print out this dict.
include unique elements of the inputted list. Under the function, write code
4. Take in 5 int inputs from the user and add them together. The catch is that you can no longer assume that what the user enters is a valid int. If the user enters an invalid input, print an error message and make the user input the int again until all 5 int values are entered correctly. Print the resulting sum.
that calls the function with a test list like so and print

1. Write a function that takes in a list data structure as input. The function should create a new list and only include unique elements of the inputted list. Under the function, write code that calls the function with a test list like so and print out the result. Remember that your code should work for all lists of integers, not just the sample test here. my_list = [1, 2, 3, 2, 1, 4] unique_list get_unique_list(my_list) print(unique_list) = $ python script_1.py [1, 2, 3, 4] 2. Write a function that takes in two dict data structures as input. Both dicts map str->int (the keys are strings and the values are integers). The function should compute a new dict which combines the two dicts by summing the values for the common keys. Keys that are not common should be left out. Use the following code to test your function, but remember that your function should for all str->int dict inputs, not just the test here. = = my_dict_1 {'a': 5, 'b': 12, 'c': 3, my_dict_2 {'b': 4, 'c': 9, 'd': 10, combined_dict = get_combined_dict(my_d print(combined_dict) = $ python script_2.py {'b': 16, 'c': 12, 'd': 19} 3. Take in a string from the user and pass it as input to a function. Have the function return a dict which keeps count of each letter (in lowercase) in the string, excluding spaces. Print out this dict. $ python script_3.py Enter a string: Hello World {'h': 1, 'e': 1, 'l': 3, 'o': 2, 'w': 1, 'r': 1, 'd': 1} 4. Take in 5 int inputs from the user and add them together. The catch is that you can no longer assume that what the user enters is a valid int. If the user enters an invalid input, print an error message and make the user input the int again until all 5 int values are entered correctly. Print the resulting sum. $ python script_4.py Enter int #1: 4 Enter int #2: a Invalid input. Please enter an int. Enter int #2: 6 Enter int #3: 5.5 Invalid input. Please enter an int. Enter int #3: 5 Enter int #4: -8 Enter int #5: -6.3 Invalid input. Please enter an int. Enter int #5: -6 Your sum is 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!