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


Groups > comp.lang.python > #91934 > unrolled thread

Re: What sort of data structure to use?

Started byDavid Palao <dpalao.python@gmail.com>
First post2015-06-03 11:22 +0200
Last post2015-06-03 11:22 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: What sort of data structure to use? David Palao <dpalao.python@gmail.com> - 2015-06-03 11:22 +0200

#91934 — Re: What sort of data structure to use?

FromDavid Palao <dpalao.python@gmail.com>
Date2015-06-03 11:22 +0200
SubjectRe: What sort of data structure to use?
Message-ID<mailman.94.1433323355.13271.python-list@python.org>
2015-06-03 10:19 GMT+02:00 David Aldrich <David.Aldrich@emea.nec.com>:
> Hi
>
>
>
> 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?
>
>
>
> Best regards
>
>
>
> David
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Hi,
What about a for loop?
paths = [pathA, pathB, pathC]
functions = (myFunc1, myFunc2)
file_lists = [fileListA, fileListB,fileListC]
for path, file_list in zip(paths, file_lists):
    for f in functions:
        f(path, file_list)

Best

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web