a dict problem

C

cheng

hi all..it a problem about dict:

print target, dict[target]

get output:

keyword
{page3.html, page2.html, page1.html}

is it some ways to change it to:

keyword
{page1.html, page2.html, page3.html}
 
S

Steven Bethard

Benji said:
I'll extrapolate from your message that you want to get the values of
the dict in sorted order. If so, here's how:
d = {'a': 1, 'b': 2, 'c':3}
d {'a': 1, 'c': 3, 'b': 2}
v = d.values()
v [1, 3, 2]
v.sort()
v
[1, 2, 3]

Or in Python 2.4:

py> d = {'a': 1, 'b': 2, 'c':3}
py> sorted(d.values())
[1, 2, 3]
 
B

Benji York

cheng said:
> hi all..it a problem about dict:
>
> print target, dict[target]
>
> get output:
>
> keyword
> {page3.html, page2.html, page1.html}
>
> is it some ways to change it to:
>
> keyword
> {page1.html, page2.html, page3.html}

First, I would recommend you always post actual code and its output.
It is much easier for people to help you that way. Also, "dict" is
not a good variable name because it shadows the built-in of the same
name.

I'll extrapolate from your message that you want to get the values of
the dict in sorted order. If so, here's how:
>>> d = {'a': 1, 'b': 2, 'c':3}
>>> d {'a': 1, 'c': 3, 'b': 2}
>>> v = d.values()
>>> v [1, 3, 2]
>>> v.sort()
>>> v
[1, 2, 3]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,240
Messages
2,571,211
Members
47,845
Latest member
vojosay

Latest Threads

Top