C
C
CreativeStory2018-10-20 14:10:49
Python
CreativeStory, 2018-10-20 14:10:49

How to remove a value from a list?

How to remove the value of the second list from the list, if it is present?

a = 'test'
b = 'test stroka'
l = [a, b]

if a in b:
    удалить test из b
    результатом должно быть - 'stroka'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Nekrasov, 2018-10-20
@CreativeStory

a = 'test'
b = 'test stroka'

if a in b:
    b = "".join(b.split(a))

PS It's not entirely clear what you want to do. If something is wrong, then explain what you want to do.
UPD1: If you still need to replace b in the list, then you need something like this:
a = 'test'
b = 'test stroka'
l = [a, b]

if a in b:
    b = "".join(b.split(a))
    l[1] = b

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question