Fast list traversal
dineshv
dineshbvadhia at hotmail.com
Sun Nov 2 03:07:04 EST 2008
On Nov 2, 1:00 am, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Sun, 2 Nov 2008 00:25:13 -0700 (PDT), dineshv
> <dineshbvad... at hotmail.com> declaimed the following in comp.lang.python:
>
> > I want to see if there is an alternative method for fast list
> > traversal. The code is very simple:
>
> > dict_long_lists = defaultdict(list)
> > for long_list in dict_long_lists.itervalues()
> > for element in long_list:
> > array_a[element] = m + n + p # m,n,p
> > are variable numbers
>
> > The long_list's are read from a defaultdict(list) dictionary and so
> > don't need initializing. The elements of long_list are integers and
> > ordered (sorted before placing in dictionary). There are > 20,000
>
> Out of curiosity, what code is used to put the values in? The sample
> you give above is creating an empty dictionary rigged, if I understand
> the help file, to automatically give an empty list if a non-existent key
> is requested. But in your loop, there is no possibility of a
> non-existent key being requested -- .itervalues() will only traverse
> over real data (ie; keys that DO exist in the dictionary).
>
> And, if you are sorting a list "before placing in dictionary", why
> need the defaultdict()? A plain
>
> dict[key] = presorted_list_of_integers
>
> would be sufficient.
>
> Or do you mean to imply that you are using something like:
>
> thedefaultdict[key].append(single_value)
> thedefaultdict[key].sort()
>
> EACH time you obtain another value from where-ever? If so, that's going
> to be the biggest time sink...
>
> > What is the fastest way to traverse these long_list's sequentially
> > from the beginning to the end? Maybe there is another data structure
> > that can be used instead of a list.
>
> So far as I know, the list IS the fastest structure available for
> sequential processing.
> --
> Wulfraed Dennis Lee Bieber KD6MOG
> wlfr... at ix.netcom.com wulfr... at bestiaria.com
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: web-a... at bestiaria.com)
> HTTP://www.bestiaria.com/
dict_long_lists is a dictionary of lists and is NOT empty. Thank-you
More information about the Python-list
mailing list