search_value , .index. .insert value ( +1).
, search_value lst. try...except ValueError, .index. lst, .insert; .
def insert_after(lst, search_value, value):
try:
lst.insert(lst.index(search_value)+1, value)
except ValueError:
lst.append(search_value)
:
>>> l = [4, 2, 6, 7, 8, 1]
>>> insert_after(l, 7, 5)
>>> l
[4, 2, 6, 7, 5, 8, 1]
?
:
list1.insert(search_value+1,value)
, . .insert . search_value+1 , .
, , , .index - , , .insert.
, .index?
, , for-loop, , , . enumerate().
, , , .index, - :
for i, e in enumerate(lst):
if e == search_value:
lst.insert(i+1, value)