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} 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
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] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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 :...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |