-1

I have a large string stored in a list. I only need to extract the URL and dump the rest of the string. How would I do this? The bold is all I need and for every element in the list, the ? is the cut off where I want to capture the URL. I am not sure if this will the 'u' disappear as well.

lst =[u'https://images.com/candles.jpg?asdkfasdkfihawklwie']

Just want to emphasis that I want to drop everything after the question mark including the question mark itself for every element in the list. Only need the URL.

Thank you in advance.

RustyShackleford
  • 3,462
  • 9
  • 40
  • 81

1 Answers1

0

Use split with list comprehension:

L = [x.split('?', 1)[0] for x in lst]

As @Martijn Pieters commented faster is use partition:

L = [x.partition('?')[0] for x in lst]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252