The following example shows the storing of the data and accessing the data from dictionary variable.The accessing of dictionary variable data is not a orderas what we are storing.
Is my understanding is correct?.Is it possible to retrievethe dictiondary variable data in a order,as what we store?
Thanks in advance
PSB - >>> dict1= {"E1":[1,2,6,5],"E2":[2,3,7,6],"E3":[3,4,8,7],"E4":[5,6,10,9],"E5":[6,7,11,10],"E6":[7,8,12,11]}
-
>>> print dict1
-
{'E5': [6, 7, 11, 10], 'E4': [5, 6, 10, 9], 'E6': [7, 8, 12, 11], 'E1': [1, 2, 6, 5], 'E3': [3, 4, 8, 7], 'E2': [2, 3, 7, 6]}
-
>>>
6 1972
The following example shows the storing of the data and accessing the data from dictionary variable.The accessing of dictionary variable data is not a orderas what we are storing.
Is my understanding is correct?.Is it possible to retrievethe dictiondary variable data in a order,as what we store?
Thanks in advance
PSB - >>> dict1= {"E1":[1,2,6,5],"E2":[2,3,7,6],"E3":[3,4,8,7],"E4":[5,6,10,9],"E5":[6,7,11,10],"E6":[7,8,12,11]}
-
>>> print dict1
-
{'E5': [6, 7, 11, 10], 'E4': [5, 6, 10, 9], 'E6': [7, 8, 12, 11], 'E1': [1, 2, 6, 5], 'E3': [3, 4, 8, 7], 'E2': [2, 3, 7, 6]}
-
>>>
the typical way to do it is by sorting the keys -
>>> for keys in sorted(dict1.keys()):
-
... print keys, dict1[keys]
-
...
-
E1 [1, 2, 6, 5]
-
E2 [2, 3, 7, 6]
-
E3 [3, 4, 8, 7]
-
E4 [5, 6, 10, 9]
-
E5 [6, 7, 11, 10]
-
E6 [7, 8, 12, 11]
-
-
In this example the data is available in a order.But if the data is available in this order.
dict1= {E2":[2,3,7,6],"E3":[3,4,8,7],"E1":[1,2,6,5],","E4":[5,6,10,9],"E5":[6,7,11,10],"E6":[7,8,12,11],"E3":[3,4,8,7]}
Thanks
PSB
In this example the data is available in a order.But if the data is available in this order.
dict1= {E2":[2,3,7,6],"E3":[3,4,8,7],"E1":[1,2,6,5],","E4":[5,6,10,9],"E5":[6,7,11,10],"E6":[7,8,12,11],"E3":[3,4,8,7]}
Thanks
PSB
Dictionaries are NOT ordered collections. They are ramdomized for faster retreival (hashing).
In this example the data is available in a order.But if the data is available in this order.
dict1= {E2":[2,3,7,6],"E3":[3,4,8,7],"E1":[1,2,6,5],","E4":[5,6,10,9],"E5":[6,7,11,10],"E6":[7,8,12,11],"E3":[3,4,8,7]}
Thanks
PSB
pls explain clearly. do you want to sort the keys ? or the dictionary values?
sort the keys means you want E1, then E2 and so on. Sort the values means for example, you want to sort [2,3,7,6] to become [2,3,6,7]
bvdet 2,851
Expert Mod 2GB
The following example shows the storing of the data and accessing the data from dictionary variable.The accessing of dictionary variable data is not a orderas what we are storing.
Is my understanding is correct?.Is it possible to retrievethe dictiondary variable data in a order,as what we store?
Thanks in advance
PSB - >>> dict1= {"E1":[1,2,6,5],"E2":[2,3,7,6],"E3":[3,4,8,7],"E4":[5,6,10,9],"E5":[6,7,11,10],"E6":[7,8,12,11]}
-
>>> print dict1
-
{'E5': [6, 7, 11, 10], 'E4': [5, 6, 10, 9], 'E6': [7, 8, 12, 11], 'E1': [1, 2, 6, 5], 'E3': [3, 4, 8, 7], 'E2': [2, 3, 7, 6]}
-
>>>
If you want to retrieve the data in the same order it was stored, you can use lists or tuples. -
>>> keyList = ["E1", "E2", "E3", "E4"]
-
>>> dataList = [[1,2,6,5],[2,3,7,6],[3,4,8,7],[5,6,10,9]]
-
>>> for i, key in enumerate(keyList):
-
... print '%s = %s' % (key, dataList[i])
-
...
-
E1 = [1, 2, 6, 5]
-
E2 = [2, 3, 7, 6]
-
E3 = [3, 4, 8, 7]
-
E4 = [5, 6, 10, 9]
-
>>>
A dictionary stores data randomly. Data items can be appended to lists as they are acquired. Retrieving dictionary data from a sorted key list will not necessarily match the order of data acquisition.
Is this what you are trying to do?
Hi,
Thanks for the reply
Yes,You are right.
PSB
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Thomas Philips |
last post by:
I want to print "1 spam 4 you" using a formatted string that gets its
inputs from the dictionary d={'n1':1, 's1':'spam', 'n2':4}. To do so,
I write
>>> x="%('n1')d %('s1')s %('n2')d you"
>>> x...
|
by: Alan Silver |
last post by:
Hello,
I have a server running Windows Server 2003, on which two of the web
sites use the MegaBBS ASP forum software. Both sites suddenly developed
the same error, which seems to be connected to...
|
by: barbaros |
last post by:
Hello everybody,
I need some advice on the following problem.
I want to write a program (in C or C++) which will
build a huge dictionary (hash array, if you prefer).
The keys are strings, the...
|
by: Alex Maghen |
last post by:
I want to create an object which is attached to the specific user session and
I want to be able to access that object directly throughout the Pages, Page
Controls, and Master Pages of the site.
...
|
by: Martin Pöpping |
last post by:
Hello,
I´ve implemented a Hashtable with Int-Keys and Double Values.
Now I want to get the i-th Int-Key of my hashtable.
How do I do that?
I tried it like that:
ICollection intKeys =...
|
by: Sike |
last post by:
Hi everyone,
I've been browsing this and a few other related newsgroups trying to
get my head around this problem, and so far all the trails seem to go
cold, without an acceptable solution being...
|
by: GTXY20 |
last post by:
Hi All,
I have been able to create a successful application with Python but I am being asked to create in VB.
I have a text file with the following data:
1,a
1,b
1,c
2,a
|
by: Peter |
last post by:
Hi, I have a Dictionary<key, valuewhich is accessed by three threads.
One thread puts my value objects in the dictionary (occasionally), and
also updates the contents of existing value objects -...
|
by: Mitko Haralanov |
last post by:
I have a Python module that I have written using the C API and I am
having a problem accessing a dictionary from that module.
Here is what I have done:
1. In my init function I call
module =...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |