Question

In: Computer Science

For this assignment, we will learn to use Python's built in set type. It's a great...

For this assignment, we will learn to use Python's built in set type. It's a great collection class that allows you to get intersections, unions, differences, etc between different sets of values or objects.

1. Create a function named common_letters(strings) that returns the intersection of letters among a list of strings. The parameter is a list of strings.

For example, you can find the common letter in the domains/words statistics, computer science, and biology. You might easily see it, but you need to write Python code to compute the answer. In order to pass the tests you must use the set api.

Solutions

Expert Solution

# Define a function common_letters() that accepts a

# list of strings. It returns the intersection of

# letters from a given list of strings.

def common_letters(strings):

    # Create and initialize a variable 'res' to store

    # first string from a list of strings passed.

    res=strings[0]

    # Use for loop to traverse through a list of

    # strings.

    for letters in strings:

        # Store the set of common letters from previous

        # and current string into res variable.

        res=set(res).intersection(letters)

    

    # Return the list of common letters from list of strings.

    return res

# Define a list of strings.

strings=['statistics','computer science', 'biology']

# Call the common_letters() function.

intersection=common_letters(strings)

# Display the result returned by common_letters().

print(str(intersection))


Related Solutions

This question set will use the following scenario that we saw on last week’s homework assignment:...
This question set will use the following scenario that we saw on last week’s homework assignment: Scores on the Wechsler Adult Intelligence Scale- Third Edition (WAIS-III) are nationally standardized to be normally distributed with a mean of 100 and standard deviation of 15. A psychologist has a dataset containing the WAIS-III scores from a random sample of 50 adults who are members of a specific organization. They want to know if there is evidence that the mean WAIS-III score in...
We learn that business-type activities of governments are accounted for in a fashion similar to those...
We learn that business-type activities of governments are accounted for in a fashion similar to those carried out by businesses. It is easy to understand that accounting for these services is done on a full accrual basis of accounting; however, give your opinion on the way in which this integrates with the modified basis of accounting used by governmental funds. Use the textbook and GASB materials to support your position. Analyze the various types of business-type funds used in governmental...
C++ good documentation as well as explanations would be great. In this HW assignment we will...
C++ good documentation as well as explanations would be great. In this HW assignment we will simulate a car wash and calculate the arrival time, departure time and wait time for each car that came in for a car wash. We will use the following assumptions about our car wash: Each car takes 3 minutes from start of the car wash to the end. Only one car can be in the car wash at a time. This mean that if...
Objective: The objective of this assignment is to learn about how to use common concurrency mechanism.        ...
Objective: The objective of this assignment is to learn about how to use common concurrency mechanism.         Task: In this assignment you will be doing the followings: 1. Write a program (either using Java, python, C, or your choice of programming language) to create three threads: one for deposit function and two for withdraw functions. 2. Compile and run the program without implementing any concurrency mechanism. Attach your output snapshot. 3. Now, modify your program to implement any concurrency mechanism. Compile...
Using the R built-in data set called Chick Weight, we want to compare the mean weight...
Using the R built-in data set called Chick Weight, we want to compare the mean weight across the different types of Diet. IMPORTANT: We only want to compare chicks at the final value of Time, 21. In this problem, use ?? = 0.05. Make a boxplot to compare weight across the different types of Diet. Based on the boxplot, describe any differences (or lack of differences) you see. Run an ANOVA to compare weight across the different types of Diet....
Individual Assignment #4: We have covered a great deal of ground and information between the last...
Individual Assignment #4: We have covered a great deal of ground and information between the last assignment and this assignment. I would like you to focus your time on two on the most forgotten areas of training and development. Those two areas include analysis and evaluation. 1. Define the term needs analysis and evaluation 2.Describe the components of a needs analysis 3.Explain how you would conduct a needs analysis at BP Amoco 4.Describe the levels of evaluation and which ones...
From the reading this week, you will learn about the basic model that we use to...
From the reading this week, you will learn about the basic model that we use to explain the entire economy, aggregate demand-aggregate supply. All of the macroeconomic material is related to this model: GDP, inflation, unemployment. In chapter 12, you’ll read about how fiscal policy can affect the economy. The fiscal policy tools that you read about in this chapter are meant to adjust the aggregate demand side of the economy. But there is a debate about whether this is...
In this assignment, we will explore some simple expressions and evaluate them. We will use an...
In this assignment, we will explore some simple expressions and evaluate them. We will use an unconventional approach and severely limit the expressions. The focus will be on operator precedence. The only operators we support are logical or (|), logical and (&), less than (<), equal to (=), greater than (>), add (+), subtract (-), multiply (*) and divide (/). Each has a precedence level from 1 to 5 where higher precedence operators are evaluated first, from left-to-right. For example,...
The goal of this assignment is to implement a set container using linked lists. Use the...
The goal of this assignment is to implement a set container using linked lists. Use the authors bag3.h and bag3.cpp as a basis for implementing your set container using linked lists. The authors bag3.h and bag3.cpp can be found here https://www.cs.colorado.edu/~main/chapter5/ Since you are using the authors bag3.h and bag3.cpp for your Set container implementation, make sure that you change the name of the class and constructors to reflect the set class. Additionally you will need to implement the follow...
This week we will learn about the "They Say I Say" thesis statement. You will use...
This week we will learn about the "They Say I Say" thesis statement. You will use this type of thesis statement in your essay writing. This type of statement allows you to establish a place within the conversation of the subject rather then simply just present your view. It requires that you combine your prior knowledge with other's views and can established a thoughtful, educated and credible argument. You have been preparing for this with your prior active reading and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT