I have a string...
my_string="The way you see people is the way you treat them and the Way you treat them is what they become"
my def should return this:
{2: ['is'],
3: ['and', 'see', 'the', 'way', 'you'],
4: ['them', 'they', 'what'],
5: ['treat'],
6: ['become', 'people']}
My solution returns:
{3: {'you', 'see', 'way', 'and', 'the'},
6: {'become', 'people'},
2: {'is'},
5: {'treat'},
4: {'what', 'them', 'they'}}
i need to sorted that dictionary by key and change value's class...my values class is {} but i want [] My solution:
def n_letter_dictionary(my_string):
my_string=my_string.lower().split()
sample_dictionary={}
r=[]
for word in my_string:
lw=len(word)
if lw in sample_dictionary:
sample_dictionary[lw].add(word)
else:
sample_dictionary[lw] = {word}
return sample_dictionary
print(n_letter_dictionary("The way you see people is the way you treat them
and the Way you treat them is what they become"))
how can i do this?anyone can help?