I have a python script with this list:
blocks = [
"item-1",
"item-2",
"item-3.0;item-3.1;item-3.2"
]
I have tried this:
for (i, block) in enumerate(blocks):
if ";" in block:
[blocks.insert(i, c) for c in block.split(";")]
else:
blocks.insert(i, block)
To get this:
blocks = [
"item-1",
"item-2",
"item-3.0",
"item-3.1",
"item-3.2"
]
Unfortunately my code keeps overwriting the the elements in the list, and I'm left with this:
blocks = [
"item-1",
"item-2",
"item-3.2"
]
How can I modify the script to allow me to split a string inside of a list and then insert the new sub-strings into the position of the original string without overwriting the other elements in the list?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…