SINDHAVJAY
(SINDHAV JAYDEEP)
June 17, 2022, 4:08pm
1
<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]
SINDHAV JAYDEEP:
…and run the code
You need to replace r1
values in the list with r2
values?
An example of the output you expect would help.
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]
SINDHAVJAY
(SINDHAV JAYDEEP)
June 18, 2022, 4:40am
5
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?
Start iterating over list
Put value of first list element into variable1
Do something with variable1
Loop back and put value of second list element into variable1
Do the same action in step 3 with the new value in variable1
SINDHAVJAY
(SINDHAV JAYDEEP)
June 18, 2022, 5:28am
7
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
SINDHAVJAY
(SINDHAV JAYDEEP)
June 18, 2022, 7:28am
9
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
SINDHAVJAY
(SINDHAV JAYDEEP)
June 18, 2022, 3:08pm
11
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