I am trying to use a list of strings, some of which are repeated. But I can't seem to get the right level of string nesting I need.
I am still a novice in Python, and I am confused. I read this answer and attempted to implement it, but are lists of strings somehow a special case that behave differently than lists of other types?
If I run:
old_freestream_headings='area,MM static pressure,MM relative mach number,'
old_integral_headings='dp,Impulse:0,Impulse:1,Impulse:2,'
old_forces_headings=('pressure force vector:0,pressure force vector:1,pressure force vector:2,'
'viscous force vector:0,viscous force vector:1,viscous force vector:2,')
old_headings=[old_freestream_headings*2,old_integral_headings,old_forces_headings*5]
print(filter(None,old_headings[0].split(',')))
I get as a result:
['area', 'MM static pressure', 'MM relative mach number', 'area', 'MM static pressure', 'MM relative mach number']
which is both copies of the first string.
If instead I run:
old_freestream_headings='area,MM static pressure,MM relative mach number,'
old_integral_headings='dp,Impulse:0,Impulse:1,Impulse:2,'
old_forces_headings=('pressure force vector:0,pressure force vector:1,pressure force vector:2,'
'viscous force vector:0,viscous force vector:1,viscous force vector:2,')
old_headings=[[old_freestream_headings]*2,old_integral_headings,[old_forces_headings]*5]
print(filter(None,old_headings[0].split(',')))
I get an error:
AttributeError: 'list' object has no attribute 'split'
because I am not splitting a string anymore, as old_headings[0] is now a list of two strings.
The output I would like to get is
['area', 'MM static pressure', 'MM relative mach number']
that is, apply split to only one copy of the string.
What am I doing wrong?