How to print or join specific elements of a list (Python)?

list = [8,4,3,2,5]

Is there a way to join two elements not using slice

print ' '.join(list[0:3]) #would print out the numbers in between

What if I want to print just those specific elements?

Answers


You can use Python's string formatter:

>>> arr = [8,4,3,2,5]
>>> print "{0} {3}".format(*arr)
8 2

Also, please don't name your variables after built-in functions/types such as list.


Need Your Help

PHP set active link on page using includes

php javascript jquery include navigation

So I have searched SO for an hour trying to find the answer, and also tried various methods, including this

CSS background-position not working in Mobile Safari (iPhone/iPad)

css mobile safari background-position

I have an issue with background-position in mobile safari. It works fine on other desktop browsers, but not on iPhone or iPad.