473,382 Members | 1,425 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,382 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 1292
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 = , ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.