Python Forum
Get all values of for loop with an index - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: General Coding Help (https://python-forum.io/Forum-General-Coding-Help)
+--- Thread: Get all values of for loop with an index (/Thread-Get-all-values-of-for-loop-with-an-index)



Get all values of for loop with an index - BollerwagenIng - Aug-09-2019

I've read a text file and got my ten lines with a for loop:
j = 871
i=0
counter = list(range(10))
for i in counter:
    CYC1=('\n'.join(map(str, f06FileSpecM1[j+i:j+i+1])))
    print(CYC1) [color=#2ECC71]#if I let it print here I get all lines but if I go out of the for loop I get again only the last line[/color]
    i=i+1
Now I want to get a value with the index [62:71]. Its for all ten lines the same. But if I try it with:
cmm = (CYC1[62:71]
I only get the value of the last line.
How is it possible to get all the ten values?
Thanks for your help :D


RE: Get all values of for loop with an index - Yoriz - Aug-09-2019

Append the items to a list.


RE: Get all values of for loop with an index - BollerwagenIng - Aug-09-2019

Yes! I made an append but now my new list has 10 elements. How can I split them to get every element fro 62 to72? Already tried with another for loop ://