'Create a new list with a string changing one character
I have this sting =IF(BP2=$I$1,1,IF(BQ2=$I$1,1,IF(BR2=$I$1,1,IF(BS2=$I$1,1,IF(BT2=$I$1,1,0)))))
And I need to make a list where the which would look like this:
1.=IF(BP2=$F$1,1,IF(BQ2=$F$1,1,IF(BR2=$F$1,1,IF(BS2=$F$1,1,IF(BT2=$F$1,1,0)))))
2.=IF(BP2=$G$1,1,IF(BQ2=$G$1,1,IF(BR2=$G$1,1,IF(BS2=$G$1,1,IF(BT2=$G$1,1,0)))))
3.=IF(BP2=$H$1,1,IF(BQ2=$H$1,1,IF(BR2=$H$1,1,IF(BS2=$H$1,1,IF(BT2=$H$1,1,0)))))
4.=IF(BP2=$I$1,1,IF(BQ2=$I$1,1,IF(BR2=$I$1,1,IF(BS2=$I$1,1,IF(BT2=$I$1,1,0)))))
.
.
.
21.=IF(BP2=$Z$1,1,IF(BQ2=$Z$1,1,IF(BR2=$Z$1,1,IF(BS2=$Z$1,1,IF(BT2=$Z$1,1,0)))))
Bassicaly I need the initial string to be put in a list with the characters 9,23,37,51,65 to take values from the list s[F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z].
Thank you!
Solution 1:[1]
You could do it like this :
s = "=IF(BP2=$I$1,1,IF(BQ2=$I$1,1,IF(BR2=$I$1,1,IF(BS2=$I$1,1,IF(BT2=$I$1,1,0)))))"
all_letters = ["F","G","H","I","J","K"]
result_list = [s.replace("$I$", f"${new_col}$") for new_col in all_letters]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ssayan |
