On Oct 10, 4:36 am, RossRGK [EMAIL PROTECTED] wrote:
I'm having trouble getting my head around a solution for a situation
where I need to flexibly format some text with a varying number of
embedded fields.
Here's a simplified description of my challenge...
I have a list of lists called
Kerri Reno wrote:
Ross,
I'm no expert in python, so excuse me if this is inane.
What I would do is have fmts be a dictionary where
fmts = { 3 = 'oats %0d kilos over %0d days with %0d workers',
2 = 'barley %0d lbs for %0d hours',
1 = 'apples %0d baskets'}
then something like
davidsands wrote:
The tuple() type-conversion function will do what you need:
print fmts[0] % tuple(bigList[0])
print fmts[1] % tuple(bigList[1])
print fmts[2] % tuple(bigList[2])
I never thought of the tuple type conversion - that looks promising.
Thanks for that!
R.
--
Hi,
RossRGK wrote:
Kerri Reno wrote:
Ross,
I'm no expert in python, so excuse me if this is inane.
What I would do is have fmts be a dictionary where
fmts = { 3 = 'oats %0d kilos over %0d days with %0d workers',
2 = 'barley %0d lbs for %0d hours',
1 = 'apples %0d baskets'}
I'm having trouble getting my head around a solution for a situation
where I need to flexibly format some text with a varying number of
embedded fields.
Here's a simplified description of my challenge...
I have a list of lists called bigList:
bigList = [ little, small, tiny]
The sub-lists
Ross,
I'm no expert in python, so excuse me if this is inane.
What I would do is have fmts be a dictionary where
fmts = { 3 = 'oats %0d kilos over %0d days with %0d workers',
2 = 'barley %0d lbs for %0d hours',
1 = 'apples %0d baskets'}
then something like
for x in bigList: