'Python for Everybody' Chapter 9 - Dictionaries (Solved Exercises)

preview_player
Показать описание

Here is the code for the solutions:

Make sure to check out my other tutorial series on Django:

Follow me on
Рекомендации по теме
Комментарии
Автор

Fully appreciate this tutorial, I was stuck yet so close. You simplified it so well

fome
Автор

Thank you for simplifying this. Even though I understand the commands and what they do, I get so confused on the order in which things need to come together.

Grateful for your channel!

JW-muoh
Автор

So good, you really know how to simplify.

For the fifth exercise I created a variable that found the index of @ and then another variable that deleted everything before the @ and returned the result. So much more complicated.

AJMcPanda
Автор

Thank you so so so much, this helped me understand the entire chapter. I’ll def come to your videos for help in the future ❤️❤️

sliceofshelby
Автор

Thanks man. Helped a lot. Keep it up 👍

roshanrai
Автор

Excercise 2 Solution:
import string

user_file = input("Enter the name of the file: ")
fhand = open(user_file)

try:
fhand = open(user_file)

except:
print("File cannot be opened!", fhand)
exit()

counts = dict()

for line in fhand:
line.rstrip()
line.translate(line.maketrans('', '', string.punctuation))

if "From" not in line:
continue
elif "From:" in line:
continue
else:
words = line.split()
words = words[2]

if words == "Sat" or words == "Fri" or words == "Thu":
counts[words] = counts.get(words, 0) + 1

print(counts)

moviemania
Автор

Thanks a lot for this!! Are you using atom to solve?? If so what packages have you installed/recommend installing besides the terminal package??

gaurangruparelia
Автор

@aksonai at Exercise 9_3 (12:00), even though we are using a dictionary to get the histogram of emails, I always get the emails represented in the same order no matter how many times I run the code. Why is that?

kerimthedream
Автор

at 17:30 why is it necessary to initialise k as None outside the for loop: Aren't we initialising it as max_address in the for loop. Or is it just in case we have an empty dictionary?

Also, for question 4, say if we had more than one key with a max value of 5 in the dictionary, how would we get all those keys. I think this code only returns the first key with the maximum value.

I noticed this when trying to get the min values (where there are several keys in the dictionary with values of 1) and haven't yet found a solution for getting all those keys with minimum values. Any ideas? Convert the dictionary to a sorted tuple and go from there?

markkennedy
Автор

nice and clear explanation just maybe to long names for the variables :)

realtd
Автор

Do you have a solution for Exercise 1? Thanks.

Tdav
Автор

i have solved the work on exercise 4 chapter 9, am stuck in printing how many messages the person has

deng_mapeer
Автор

whoever you are I could kiss you right now, I was stuck on thi for so long. You are amazing! THank you so much

stevenfischer
Автор

Thanks a lot for this!! Are you using atom to solve?? If so what packages have you installed/recommend installing besides the terminal package??

gaurangruparelia
visit shbcf.ru