ICN_CEIL15 = soup.select_one('table:nth-child(2) > tbody > tr:nth-child(2) > td:nth-child(1) > table > tbody > tr:nth-child(4) > td').text + "'"
ICN_CEIL33 = soup.select_one('table:nth-child(2) > tbody > tr:nth-child(2) > td:nth-child(6) > table > tbody > tr:nth-child(4) > td').text + "'"
ICN_CEIL16 = soup.select_one('table:nth-child(6) > tbody > tr:nth-child(2) > td:nth-child(1) > table > tbody > tr:nth-child(4) > td').text + "'"
ICN_CEIL34 = soup.select_one('table:nth-child(6) > tbody > tr:nth-child(2) > td:nth-child(6) > table > tbody > tr:nth-child(4) > td').text + "'"
ICN_CEILs = [ICN_CEIL15, ICN_CEIL33, ICN_CEIL16, ICN_CEIL34]
for i in ICN_CEILs:
if i == "'":
i = "U/S'"
I want to change the variable in ICN_CEILs as a for statement, but it cannot be changed.
If you use print(ICN_CEILs)
before for, ["NCD'","",""]
comes out like this, and I want to change the two values ("",""
"U/S"
) to at the right end, but it doesn't change. I can't see what's wrong.
i
is a variable that is created for a while to contain the list element in the for
statement and then disappears. So even if you put a value in i
, the value of the original list does not change.
You can do it like this.
for i in range(len(ICN_CEILs)):
if ICN_CEILs[i] == "'":
ICN_CEILs[i] = "US'"
By the way, range(len(...)
is not pretty and cumbersome, so it's a little simpler if you use enumerate
for i, ele in enumerate(ICN_CEILs):
if ele == "'":
ICN_CEILs[i] = "US'"
If you change this back to list compression,
ICN_CEILs = [ "US'" if ele == "'" else ele for ele in ICN_CEILs ]
You can do it like this.
582 GDB gets version error when attempting to debug with the Presense SDK (IDE)
826 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
558 Who developed the "avformat-59.dll" that comes with FFmpeg?
561 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.