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(); //...
You will implement the MyList ADT according to the following: 1. MyList must implement the List...
You will implement the MyList ADT according to the following: 1. MyList must implement the List interface. It will look something like below: public class MyList<E> implements List<E> { ... } Note: As said in the class, when implementing an interface, you have to implement each method in it. There are a lot of methods in the List interface. We are going to address this issue below. 2. The initial capacity of MyList must be 2. This is not an...
In this Java program you will implement your own doubly linked lists. Implement the following operations...
In this Java program you will implement your own doubly linked lists. Implement the following operations that Java7 LinkedLists have. 1. public DList() This creates the empty list 2. public void addFirst(String element) adds the element to the front of the list 3. public void addLast(String element) adds the element to the end of the list 4. public String getFirst() 5. public String getLast() 6. public String removeLast() removes & returns the last element of the list. 7. public String...
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...
1. For each of the following lists, perform a bubble sort, and show the list after...
1. For each of the following lists, perform a bubble sort, and show the list after each exchange: D,B,G,F,A,C,E,H 2. Explain why the bubble sort algorithm does O (n^2) comparisons on an n-element list.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT