Home > other >  How to print each element of a list until a certain length Python
How to print each element of a list until a certain length Python

Time:11-02

How to print each element of my list to a defined length (5), so for example:

myList = ["abcdefgh", "ijklmnop"]

The output I'm looking for is:

abcde
ijklm

I've tried this (printing dates from an excel sheet):

i = 2
x =0
while i < maxR:
    valuesItems =  wb0["C"   str(rowList[i])].value
    itemDate.append(valuesItems)
    print(len(itemDate[x]))
    i = i 1
    x = x 1

But this prints "19" multiple times (the length of each element, not the element itself)

CodePudding user response:

for element in myList:
    print(element[:5])
  • Related