Newbi:list value to iterate in variable

<LIST_REPLACE = [1,2,3,4,5,6,7,8,9,10] >

<r2 = 1>

i have 10 file, to process each file i have to manually change r2 value and run the code

Is this possible i can iterate over “LIST_REPLACE : ELEMENT” TO “r2”
For ex.,
1st iteration <r2 = 1>
2nd iteration <r2=2>

Welcome, Sindhav!

Will you please edit your post to separate the code from the information? Your question is unclear.

Place your code netween “fences” of backticks like this:

```
<code here>
```

Your code will look like this when it is formatted:

LIST_REPLACE = [1,2,3,4,5,6,7,8,9,10] 

You need to replace r1 values in the list with r2 values?
An example of the output you expect would help. :slight_smile:

Is this what you are looking for…?
BEFORE [1,2,3,4,5,6,7,8,9,10]
r1 = 1
r2 = 2
AFTER [2,2,3,4,5,6,7,8,9,10]

Whole list’s element to iterable to single variable
One by one
<variable1 = 1st element of list>
<variable1= 2nd element of list>
It is kind of loop

This the process you need?

  1. Start iterating over list
  2. Put value of first list element into variable1
  3. Do something with variable1
  4. Loop back and put value of second list element into variable1
  5. Do the same action in step 3 with the new value in variable1

Yes!!!
Variable name will be same
but its value change
With each iteration

That is a basic for: loop.

data = [1,2,3,4,5,6,7,8,9,10]
for item in data:
    print(item)   #this is the "Do something with variable1" step
1 Like

Can write r3 inplace of item?

Yes. item is a name I created. You can use your own name.

“Item” means ‘one thing’.

1 Like

Man oh man!!!
Worked like charm…
I tried this solution earlier…many time.
But didnt yield desired result.
Changed word from “item” to “r2” as u said,
And all dependent value to this variable ( “r2”) changed as expected.
Thank u!!!

1 Like