Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91935

Re: What sort of data structure to use?

Date 2015-06-03 19:24 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: What sort of data structure to use?
References <41302A7145AC054FA7A96CFD03835A0A0B97DECA@EX10MBX02.EU.NEC.COM>
Newsgroups comp.lang.python
Message-ID <mailman.95.1433323492.13271.python-list@python.org> (permalink)

Show all headers | View raw


On 03Jun2015 08:19, David Aldrich <David.Aldrich@EMEA.NEC.COM> wrote:
>I have written a Python utility that performs a certain activity on some predefined sets of files.  Here is the outline of what I have written:
>
># File Set A
>pathA = 'pathA'
>fileListA = ['fileA1.txt', 'fileA2.txt']
>
># File Set B
>pathB = 'pathB'
>fileListB = ['fileB1.txt', 'fileB2.txt', 'fileB3.txt']
>
>myFunc1(pathA, fileListA)
>myFunc2(pathA, fileListA)
>
>myFunc1(pathB, fileListB)
>myFunc2(pathB, fileListB)
>
>I want to add more file sets, so I really want to add the sets to a list and iterate over the list, calling myFunc1 & myFunc2 for each item.
>
>My question is: what sort of data structure could I use to organise this, given that I want to associate a set of files with each path and that, for each set, there is an arbitrary number of files?

Based on your description I would use a dict keyed on the path, whose values 
were a set of files. A set is a preprovided data type in Python. Look it up and 
use it.

There are other alternatives, but that would be a first attempt.

Cheers,
Cameron Simpson <cs@zip.com.au>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: What sort of data structure to use? Cameron Simpson <cs@zip.com.au> - 2015-06-03 19:24 +1000

csiph-web