[Tutor] Dictionary

Alan Gauld alan.gauld at yahoo.co.uk
Sun Jan 24 04:36:11 EST 2021


On 24/01/2021 03:52, Tyriq Howell wrote:
> I was wondering how do I get the dictionary by using sys.argv 
> and then looping it to sort it from ascending order and then from descending order 

This sounds like a homework and we won;t do your homework for you.

But we can offer suggestions, answer questions, review code etc.

My first question to you is how would the dict data be passed
in using argv? (This is a very unusual way of working with
dicts BTW!)

Can you show us an example of how the program would be called
and what the resulting dictionary would look like?

The second point I'd make is you really have 2 separate issues.

1) How to construct a dict from argv - which depends on the
   answer to my question above.

and

2) how to "sort" a dictionary.

Sorting a dictionary isn't normally very helpful because you
can extract the data directly in any order you choose. But
you can sort it's keys into some order. I think in recent
python versions the built-in sorted() function works with
dictionaries try it out on some sample data and see how it
works. Then read the documentation for how to control
its sort order. If that's not clear enough come back
here and ask away.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list