expanding string variables
Michaell Taylor
Michaell.Taylor at reis.com
Wed May 24 15:09:46 EDT 2000
Please excuse the newbie question....but...
I have 7 sets of 20 dictionaries upon which I need to perform mathematical
transformations. That is, for simplicity assume that I have :
first1 = {'firstelement': 45 ....., 'fifty': 89}
first2 = {...}
...
first20 = {...}
second1 = {...}
...
second20 = {...}
..
seven20 = {...}
(each dictionary has 50 elements)
I would like to code:
dict_set_list = {"first second ... seven"}
set = string.splitfield(dict_set_list)
for group in set:
group = group1[index]*group2[index]...etc
(I loop over 'index' elsewhere) That is, I would like for the term "group"
to be expanded to first, second, ...seven, Thus
allowing python to process:
first = first1[index]*first2[index]...etc
second = second1[index]*second2[index]..etc
...
seven = seven1[index]*seven2[index]...etc
Of course my actual problem is considerably more complex else I would simply
allow the code to proliferate. (I've rarely been accused of writting pretty
code...and don't even claim to be a programmer). The actual math
expressions are considerably more complex, thus a single instance is easier
to debug than 20 such near identical instances.
I know that there is an obvious way to get this done, but this is my first
python program and I can't get the sytax of a highly speciallized
statistical language out of my mind (which incidently would do this pretty
much as written - give an delimiter or two here and there).
BTW so far Python has been a wonderful experience.
Any assistance would be greatly appreciated.
===============================================
Michaell Taylor
Senior Economist, Reis.com, New York City, USA
Associate Professor of Political Science, NTNU, Trondheim Norway
Adjuct Professor of Public Policy, University of Durban, Durban, South
Africa
More information about the Python-list
mailing list