473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

a dict problem

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}

Jul 19 '05 #1
2 1451
cheng wrote:
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]
--
Benji York
Jul 19 '05 #2
Benji York wrote:
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]
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Robin Cull | last post by:
Imagine I have a dict looking something like this: myDict = {"key 1": , "key 2": , "key 3": , "key 4": } That is, a set of keys which have a variable length list of associated values after...
2
by: GrelEns | last post by:
hello, i would like if this behaviour can be obtained from python : trap an attributeError from inside a subclassing dict class... (here is a silly examples to explain my question) class...
1
by: Alexander Kervero | last post by:
Hi ,today i was reading diveinto python book,in chapter 5 it has a very generic module to get file information,html,mp3s ,etc. The code of the example is here :...
4
by: Steven Bethard | last post by:
I'd like to subclass dict to disallow overwriting of keys, something like: >>> class SafeDict(dict): .... def __setitem__(self, key, value): .... if key in self: .... raise...
5
by: Randy Bush | last post by:
a dict written as pKey = (prefix, pLen, origin) val = dict.get(pKey) if val == None: dict = (timeB, timeB) else: if val > timeB: val = timeB if val < timeB: val = timeB
3
by: Bengt Richter | last post by:
Has anyone found a way besides not deriving from dict? Shouldn't there be a way? TIA (need this for what I hope is an improvement on the Larosa/Foord OrderedDict ;-) I guess I can just document...
15
by: George Sakkis | last post by:
Although I consider dict(**kwds) as one of the few unfortunate design choices in python since it prevents the future addition of useful keyword arguments (e.g a default value or an orderby...
3
by: aking | last post by:
Dear Python people, im a newbie to python and here...so hello! Im trying to iterate through values in a dictionary so i can find the closest value and then extract the key for that...
12
by: jeremito | last post by:
Please excuse me if this is obvious to others, but I can't figure it out. I am subclassing dict, but want to prevent direct changing of some key/value pairs. For this I thought I should override...
8
by: james_027 | last post by:
hi for example I have this dictionary dict = {'name':'james', 'language':'english'} value = 'sex' in dict and dict or 'unknown' is a right pythonic of doing this one? I am trying to get a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.