[Tutor] Tutor Digest, Vol 166, Issue 21

anish singh anish198519851985 at gmail.com
Sun Dec 24 22:46:07 EST 2017


>> However, I am stuck. I have below code which is not working.

I don't know how to achieve this programmatically: sorted by the
number of occurrences in a descending order. If two or more words
have the same count, they should be sorted
alphabetically (in an ascending order).

>
> Define "not working"
> Do you get an error message? (show us)

I am not getting any error message but i don't know
how to get the expected result.

#getting: [('just', 4), ('practice', 3), ('perfect', 2), ('youll', 1),
('makes', 1), ('get', 1), ('by', 1)]
#expected: [["just","4"],["practice","3"],["perfect","2"],["makes","1"],["youll","1"],["get","1"],["by","1"]]


> If the output different to what you expect (show us)

explained above.
>
> Have you tried printing the intermediate results?

I did but I don't know how to get what i am looking for.

> For example the dictionary before you sort it?
> Or what about using the default sort, how close is that?
>
> Don't expect us to run your code and check the output.

https://paste.pound-python.org/show/NappXV9daDMFz64yA805/

With the above code, i don't know what we can modify this to get
expected result as below:

#getting: [('just', 4), ('practice', 3), ('perfect', 2), ('youll', 1),
('makes', 1), ('get', 1), ('by', 1)]
#expected: [["just","4"],["practice","3"],["perfect","2"],["makes","1"],["youll","1"],["get","1"],["by","1"]]


More information about the Tutor mailing list