I have a list of string with variable length. I do know that the minimum length of the list is 4. How do I print the list in the following format if the list grows to more than 4?
>>> strlist = ['a', 'b', 'c', 'd', 'f', 'g'] # Unknown length
>>> print ('%s %s %s %s' % (strlist [2], strlist [0], strlist [4], strlist [5]))
c a f g
If the list expands to
[..., 'h', 'i', 'j']
then I want the output to be
c a f g h i j
Obviously, I can't put 500 "%s" in my print function if the list expands so I'm hoping there's a better way.
print('%s %s %s' % (strlist[2], strlist[0], ' '.join(strlist[4:])))?%is an operator for constructing strings -- not really anything to do withprintper se. If for a given application%isn't adequate for getting the string that you want -- construct the string some other way and then print it.