This probably has a very simple solution, but I'm just a beginner.
What I have is:
def content(L):
for i in range(len(L)):
print (i), (L[i])
Right now it only prints the index and not the string. I'm not entirely sure what the issue is, but when I switch the ordering in the last line so that (L[i]) comes first then it prints the string but not the index. I want to print both on the same line.
In Python 3.x, print is not a statement as in Python 2.x, but rather a function. You can use it like this:
print(i, L[i])
Additionally, enumerate is great for what you're trying to do:
for i, c in enumerate(L):
print(i, c)
Note that you can use print as a Python 3.x-style function in Python 2 if you import it from the __future__ package (for Python 2.6 and up):
from __future__ import print_function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With