Python Forum
Get all values of for loop with an index
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get all values of for loop with an index
#1
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
Reply
#2
Append the items to a list.
Reply
#3
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 ://
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through values and compare edroche3rd 6 628 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  Loop through json file and reset values [SOLVED] AlphaInc 2 1,961 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Replace for loop to search index position illmattic 5 1,226 Sep-03-2022, 04:04 PM
Last Post: illmattic
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,430 Jul-27-2022, 08:50 PM
Last Post: rob101
  How do loop over curl and 'put' different values in API call? onenessboy 0 1,196 Jun-05-2022, 05:24 AM
Last Post: onenessboy
  Loop through values in dictrionary and find the same as in previous row Paqqno 5 1,839 Mar-27-2022, 07:58 PM
Last Post: deanhystad
  How to add for loop values in variable paulo79 1 1,410 Mar-09-2022, 07:20 PM
Last Post: deanhystad
  For loop index out of bounds armitron121 2 2,617 Feb-08-2022, 04:23 PM
Last Post: armitron121
Exclamation Compare values in a for loop. penahuse 1 2,336 Feb-22-2021, 07:01 AM
Last Post: buran
  returning values in for loop Nickd12 4 11,849 Dec-17-2020, 03:51 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020