Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 2

Write a program that counts how often cach word occurs in a text file.

Problem 3

What is the difference between a set and a list?

Problem 4

Implement the sieve of Eratosthenes: a function for computing prime numbers, known to the ancient Greeks. Choose an integer \(n\). This function will compute all prime numbers up to \(n\). First insert all numbers from 1 to \(n\) into a set. Then erase all multiples of 2 (except 2); that is, \(4,6,8,10,12 \ldots .\) Erase all multiples of 3 , that is, \(6,9,12,15, \ldots\). Go up to \(\sqrt{n}\). The remaining numbers are all primes.

Problem 4

What is the difference between a list and a dictionary?

Problem 6

Consider a program that manages a schedule of classes. Should it place the mecting information into a list, set, or dictionary? Explain your answer.

Problem 6

Write a program that reads a Python source file and produces an index of all identifiers in the file. For each identifier, print all lines in which it occurs. For simplicity, consider any string consisting only of letters, numbers, and underscores an identificr.

Problem 7

Write a program that can store a polynomial such as $$ p(x)=5 x^{10}+9 x^{7}-x-10 $$ as a list of terms. A term contains the coefficient and the power of \(x\). For example, you would store \(p(x)\) as $$ (5,10),(9,7),(-1,1),(-10,0) $$

Problem 7

One way of implementing a calendar is as a dictionary that maps dates to event descriptions. However, that only works if there is a single event for a given date. What type of complex structure can you use to allow for multiple events on a given date?

Problem 8

It is customary to represent the months of the year as an integer value. Suppose you need to write a program that prints the month name instead of the month number for a collection of dates. Instead of using a big if/elif/else statement to select the name for a given month, you can store the names in a structure. Should the names be stored in a list, set, or dictionary? Explain your answer. Suppose you frequently need to carry out the opposite conversion, from month names to integers. Would you use a list, set, or dictionary? Explain your answer.

Problem 9

If Python did not provide the set container, but you needed one in your program, what type of container could you use instead? Explain your answer.

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks