Reputation: 4405
Feels like this should be easy, but I can't find the right keywords to search for the answer.
Given ['"https://container.blob.core.windows.net/"']
as results from a python statement...
...how do I extract only the URL and drop the ['"
and "']
?
Upvotes: 2
Views: 2433
Reputation: 46
How about using regex??
In [35]: url_list = ['"https://container.blob.core.windows.net/"']
In [36]: url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\), ]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', url_list[
...: 0])[0]
In [37]: print(url)
https://container.blob.core.windows.net/
Upvotes: 2
Reputation: 38552
How about getting first element using list[0]
and remove the single quotes from it using replace()
or strip()
?
print(list[0].replace("'",""))
OR
print(list[0].strip("'")
Upvotes: 1
Reputation: 11949
You want the first element of the list without the first and last char
>>> l[0][1:-1]
'https://container.blob.core.windows.net/'
Upvotes: 5
Reputation: 453
try:
a = ['"https://container.blob.core.windows.net/"']
result = a[0].replace("\"","")
print(result)
Result:
'https://container.blob.core.windows.net/'
As a python string.
Upvotes: 1