Skip to content

Feedback homework #3

Hi Yen, mình có feedback cho bạn như sau:

  • Ex 2: để remove [2,3] bạn có thể viết là t=tuple(item for item in t if t.count(item) == 1)
  • Ex 3: để sort dict theo value và print ra keys bạn có thể làm như sau print(sorted(d, key=d.get)), để count word bạn có thể viết là
import collections
string = "Python is an easy language to learn"
print(dict(collections.Counter(string.replace(' ',''))))

hoặc

s = "Python is an easy language to learn"
s = s.replace(' ','')
print(dict((c,s.count(c)) for c in set(s)))

Cheers!

Edited by Cuong Tran