Question

In: Computer Science

1. Dictionaries and Lists. a) Implement a list of student dictionaries containing the following data: name:...

1. Dictionaries and Lists.

a) Implement a list of student dictionaries containing the following data:

name: Andy, classes: ET580 MA471 ET574

name: Tim, classes: ET574 MA441 ET575

name: Diane, classes: MA441 MA471 ET574

name: Lucy, classes: ET574 ET575 MA471

name: Steven, classes: ET574 MA441 ET580

b) Implement a dictionary of courses and set each courses enrollment to 0: ET580: 0 ET574: 0 ET575: 0 MA441: 0 MA471: 0

c) Use a loop and if statements to read class data from the list of students and update the enrollment for each course.

d) Print the updated list of courses. If the above steps are done correctly your output should match the output example.

Output Example

ET580 2 ET575 2 ET574 5 MA441 3 MA471 3

Solutions

Expert Solution

Have a look at the below code. I have put comments wherever required for better understanding. Since any specific language was not mentioned, I have used Python, it will be easy to understand.

# a) Implement a list of student dictionaries 

list = {"Andy":["ET580","MA471","ET574"],"Tim":["ET574","MA441","ET575"],"Diane":["MA441","MA471","ET574"],"Lucy":["ET574","ET575","MA471"],"Steven":["ET574","MA441","ET580"]}
# b)  Implement a dictionary of courses and set each courses enrollment to 0
courses = {"ET580":0,"ET574":0,"ET575":0,"MA441":0,"MA471":0}

# c) Use a loop and if statements to read class data from the list of students and update the enrollment for each course.
for student in list:
  for course in list[student]:
    courses[course]+=1 

# d) Print the updated list of courses
print(courses) # Output: {'ET580': 2, 'ET574': 5, 'ET575': 2, 'MA441': 3, 'MA471': 3}

Happy Learning!


Related Solutions

Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: a. def count_character(text, char): """ Count the number of times a character occurs in some text. Do not use the count() method. """ return 0 b. def count_sentences(text): """...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: g. def big_words(text, min_length=10): """ Return a list of big words whose length is at least min_length """ return [] h. def common_words(text, min_frequency=10): """ Return words occurring at...
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.
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score (int). A constructor expects a name as a parameter. A method getLevel to get the level(char) of the student. score level table: A: score >= 90 B: score >= 80 and < 90 C: score >= 60 and < 80 D: score < 60 Example:          Student student = new Student("Zack"); student.score = 10; student.getLevel(); // should be 'D'. student.score = 60; student.getLevel(); //...
Name the exchange lists and identify a food typical of each list. Explain how the exchange...
Name the exchange lists and identify a food typical of each list. Explain how the exchange system groups foods and what diet-planning principles the system best accommodates. 3 What information can you expect to find on a food label? How can this information help you choose between two similar products? 4. What are the daily values? How can they help you meet health recommendations?5. Describe the path food follows as it travels through the digestive system. Summarize the muscular actions...
Describe the following four types of lists: 1) Master Risks List 2) Risks by Services List...
Describe the following four types of lists: 1) Master Risks List 2) Risks by Services List 3) Top Risks List 4) Retired Risks List
Change program linkedListClass to the linked list for student items (a student item contains id, name...
Change program linkedListClass to the linked list for student items (a student item contains id, name and score, where the id is used as key) and test it in the main method. You can define a student item using a class of student. given the following codes; import java.util.*; public class linkedListClass {    public Node header;    public linkedListClass()    {        header = null;    }    public final Node Search(int key)    {        Node...
Define and describe data dictionaries and process descriptions Identify and justify your comments to the following...
Define and describe data dictionaries and process descriptions Identify and justify your comments to the following question: Was the subject of improving the forms a physical implementation issue?
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g....
Creating a list/tuple 3.Given a list of tuples containing student first names and last names e.g. (“John”, “Doe”) that represents a class. Ask the user for a students first and last name and check if that student is a member of the class.
Develop an algorithm to implement an employee list with employee ID ,name designation and department using...
Develop an algorithm to implement an employee list with employee ID ,name designation and department using link list and perform the following operation on the list i)add employee details based on department ii)remove employee details iv)count the number of employee in each department
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT