I have a simple question, if I have an array of strings in python: ['a', 'b', 'c', 'd'] is there a way that I can compare another string and if it exists in the array delete that value and everything after it? I'm new to python and I'm not too familiar with the syntax but pseudocode:
s = 'b'
array = ['a', 'b', 'c', 'd']
if b exists in array
remove b and elements after
so the new array would simply be ['a']. Any help would be much appreciated!
s = 'b'
array = ['a', 'b', 'c', 'd']
if s in array:
del array[array.index(s):]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With