简体   繁体   中英

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!

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM