473,287 Members | 1,708 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,287 software developers and data experts.

Lists and Sublists

We have a list of N (>2,000) keywords (of datatype string). Each of
the N keywords has associated with it a list of names of varying
numbers. For example, keyword(1) will have a list of L1 names
associated with it, keyword(2) will have a list of L2 names associated
with it and so on with L1 not equal to L2 etc. All keywords and names
are immutable.

Given a keyword(n) , we want to get hold of the associated list of Ln
names.

At anytime, we also want to add keywords to the list of N keywords,
and to any of the associated Ln lists - both of which will grow to
very large sizes.

The data will be read into the Python data structure(s) from disk
storage.

I am struggling to work out what is the ideal Python data structure
for the above. Any help would be greatly appreciated.

Dinesh

Oct 23 '07 #1
3 1288
I am struggling to work out what is the ideal Python data structure
for the above. Any help would be greatly appreciated.
The normal way is to use a dictionary of lists. The key would be the
dictionary key, which would contain a list or a list of lists, that is
each name would be an element of the list unless the name is more than
one word, in which case each name would be converted to a list and
appended to the key. Some pseudo-code
if key in name_dic:
name_dic[key] += [name] ## converted to list
If this doesn't work, then SQLite can be used in memory. There are
examples on the website.

Oct 23 '07 #2
dineshv a écrit :
We have a list of N (>2,000) keywords (of datatype string). Each of
the N keywords has associated with it a list of names of varying
numbers. For example, keyword(1) will have a list of L1 names
associated with it, keyword(2) will have a list of L2 names associated
with it and so on with L1 not equal to L2 etc. All keywords and names
are immutable.

Given a keyword(n) , we want to get hold of the associated list of Ln
names.

At anytime, we also want to add keywords to the list of N keywords,
and to any of the associated Ln lists - both of which will grow to
very large sizes.

The data will be read into the Python data structure(s) from disk
storage.

I am struggling to work out what is the ideal Python data structure
for the above. Any help would be greatly appreciated.
keywords = {}
keywords['python'] = ['fun', 'simple']
keywords['another_p_language'] = ['line noise', 'cryptic']
keywords['python'].append('readable')

HTH
Oct 23 '07 #3
On 10/24/07, Bruno Desthuilliers
<bd*****************@free.quelquepart.frwrote:
dineshv a écrit :
We have a list of N (>2,000) keywords (of datatype string). Each of
the N keywords has associated with it a list of names of varying
numbers. For example, keyword(1) will have a list of L1 names
associated with it, keyword(2) will have a list of L2 names associated
with it and so on with L1 not equal to L2 etc. All keywords and names
are immutable.

Given a keyword(n) , we want to get hold of the associated list of Ln
names.

At anytime, we also want to add keywords to the list of N keywords,
and to any of the associated Ln lists - both of which will grow to
very large sizes.

The data will be read into the Python data structure(s) from disk
storage.

I am struggling to work out what is the ideal Python data structure
for the above. Any help would be greatly appreciated.

keywords = {}
keywords['python'] = ['fun', 'simple']
keywords['another_p_language'] = ['line noise', 'cryptic']
keywords['python'].append('readable')
To add you may want to have a look at "shelve" module , in case you
want to store this object to a file. It can be useful if the data set
is large and does not change frequently and you would want to save on
some startup time .

cheers,

--
--
Amit Khemka
Oct 24 '07 #4

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

Similar topics

21
by: Hilde Roth | last post by:
This may have been asked before but I can't find it. If I have a rectangular list of lists, say, l = ,,], is there a handy syntax for retrieving the ith item of every sublist? I know about for i...
0
by: saoirse_79 | last post by:
I have a list of lists as follows: , , ] I want to be able to read each character and compare it with all characters at the same positon in all sublists. Is this possible. I have tried a few...
0
by: saoirse_79 | last post by:
I was wondering if anyone knows a short way to do the following.. I have 2 lists of list..eg I want to comapre the two lists of lists and count the number of times the sublists match. In the...
8
by: Charlotte Henkle | last post by:
Hello; I'm pondering how to count the number of times an item appears in total in a nested list. For example: myList=,,] I'd like to know that a appeared three times, and b appeared twice,...
7
by: Kay Schluehr | last post by:
I want to manipulate a deeply nested list in a generic way at a determined place. Given a sequence of constant objects a1, a2, ..., aN and a variable x. Now construct a list from them recursively:...
51
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
6
by: Tekkaman | last post by:
I have a list of lists and I want to define an iterator (let's call that uniter) over all unique elements, in any order. For example, calling: sorted(uniter(, , ])) must return . I tried the...
10
by: Anton Vredegoor | last post by:
Python's sorting algorithm takes advantage of preexisting order in a sequence: #sort_test.py import random import time def test(): n = 1000 k = 2**28
19
by: Dr Mephesto | last post by:
Hi! I would like to create a pretty big list of lists; a list 3,000,000 long, each entry containing 5 empty lists. My application will append data each of the 5 sublists, so they will be of...
3
by: Qbert16 | last post by:
Hi, I'm quite new to python and am looking for help with lists inside lists This is an example I'm trying to do. I have the following thesaurus set... thesaurus = , ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.