FLexible formatted text involving nested lists?

RossRGK nobody at nospam.noway
Fri Oct 10 09:49:46 EDT 2008


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
>   for x in bigList:
>      print fmts[len(x)] % x
> 
> I didn't test this, but in theory it should work.
> 
> Hope this helps,
> Kerri


Thx for the suggestion - i think that would match the number of fields 
to the number of parameters in the specific example but not the general 
case.  ie fmts[3] could have 3fields this time, but might be 2 another 
time or something else.

Plus I don't think print will accept a list 'x' in the %x part of it.



More information about the Python-list mailing list