Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Part 2

Write a function called missing_letters that takes a string parameter and returns a new string with all the letters of the alphabet that are not in the argument string. The letters in the returned string should be in alphabetical order.

Your implementation should use a histogram from the histogram function. It should also use the global variable alphabet. It should use this global variable directly, not through an argument or a local copy. It should loop over the letters in alphabet to determine which are missing from the input parameter.

The function missing_letters should combine the list of missing letters into a string and return that string.
Part 1

Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters. Otherwise, it should return False.

Implement has_duplicates by creating a histogram using the histogram function above. Do not use any of the implementations of has_duplicates that are given in your textbook. Instead, your implementation should use the counts in the histogram to decide if there are any duplicates.

Write a loop over the strings in the provided test_dups list. Print each string in the list and whether or not it has any duplicates based on the return value of has_duplicates for that string. For example, the output for "aaa" and "abc" would be the following.

aaa has duplicates
abc has no duplicates

Print a line like one of the above for each of the strings in test_dups.
Programming Assignment
Start with the following Python code.

alphabet = "abcdefghijklmnopqrstuvwxyz"

test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]

test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]

# From Section 11.2 of:

# Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press.

def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 1
else:
d[c] += 1
return d

Copy the code above into your program but write all the other code for this assignment yourself. Do not copy any code from another source.
Next consider the invert_dict function from Section 11.5 of your textbook.

# From Section 11.5 of:
# Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press.

def invert_dict(d):
inverse = dict()
for key in d:
val = d[key]
if val not in inverse:
inverse[val] = [key]
else:
inverse[val].append(key)
return inverse

Modify this function so that it can invert your dictionary. In particular, the function will need to turn each of the list items into separate keys in the inverted dictionary.

Run your modified invert_dict function on your dictionary. Print the original dictionary and the inverted one.

Include your Python program and the output in your Learning Journal submission.

Describe what is useful about your dictionary. Then describe whether the inverted dictionary is useful or meaningful, and why
Create a Python dictionary that returns a list of values for each key. The key can be whatever type you want.

Design the dictionary so that it could be useful for something meaningful to you. Create at least three different items in it. Invent the dictionary yourself. Do not copy the design or items from some other source.

.
Describe how tuples can be useful with loops over lists and dictionaries, and give Python code examples. Create your own code examples. Do not copy them from the textbook or any other source.

Your descriptions and examples should include the following: the zip function, the enumerate function, and the items method.
Write a program that asks for a student for his/her offering code in computer programming 1. Your program will determine what set the student belong based on the following:
if the offer code is 16548, the student's set is A
if the offer code is 16558, the student's set is B
if the offer code is

16568, the student's set is C
if the offer code is 17020, the student's set is D

what is the code to change the color of a turtle in Python?


We Filipinos are quite known for the habit

of leaving at least one of the many pieces

of food on the plate as it can't be equally

divided among all at most times. Just like

when 3 people decide to eat a pizza of 10

Slices, there will often be at least one slice

left on the box. To accurately show just

how many pieces of things are left when

divided by a certain number, we code it

using modulo.

Care to do it for me?

Input

A line containing two integers separated

by a space.

10 3

Output

A single line containing an integer.


Read through this program carefully and try to analyze what is going on in each line of code (each line of code is performing more than one task).


LATEST TUTORIALS
APPROVED BY CLIENTS