Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

>Solution :

for element in myList:
    print(element[:5])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading