'Python for Everybody' Chapter 10 - Tuples (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
Рекомендации по теме
Комментарии
Автор

How do you make a complicated issue so simple? You’re really a good teacher 👏

halimbilir
Автор

thanks. was just lost on the 3rd exercise on how to make it exclusively the alphabet cause i couldn't remove punctuation. but simbly creating a string variable with the alphabet is pretty simple and clever.

ok
Автор

Great videos man. You do a good job of breaking down the assignments.

jonathanhinkey
Автор

After 19th line, I have an easy way to do it, so if you want to shorter your codes try this one.

import string


counts= 0
dict_counts = dict()
relative_lst = list()

inp = input('Enter file name: ')
if len(inp) < 1 : inp = 'mbox-short.txt'
fh = open(inp)

for line in fh:
line = line.translate(str.maketrans('', '', string.digits))
line = line.translate(str.maketrans('', '', string.punctuation))
line = line.lower()

# Removes numbers and punctuation then sets all letters to lower case
words = line.split()
for word in words:
for letter in word:
# Count each letter for relative frequencies
counts += 1
if letter not in dict_counts:
dict_counts[letter] = 1
else:
dict_counts[letter] += 1

# After this is the part we can shorten the code for the sorted list.

x = sorted ( [ (v, k) for k, v in dict_counts.items() ], reverse=True )

for v, k in x :
print ( k, "=", v / counts )

magnexgame
Автор

Thank you, this has helped a lot! I am still trying to make head and tail of getting solutions to problems.

radiodk
Автор

thank you so much!! your solution is the best!!

stephaniegu
Автор

🙌🏽🙌🏽Great content, where do you get your exercise questions?

pulemabote
Автор

I was doing everything good. Thanks for your video. Just a question: why should I put .read() to make then the file lower?

flaviobrienza
Автор

Hey . Thanks for the help but every time I type in time=line.split()[5], Iget a list index out of range error.
so I usually cannot progess past this line of the code even when trying other methods. Not sure what I am doing wrong. Thank you in advance!

stevenfischer
Автор

I didn't understand the question itself. What output is needed ?

sagarjadhav