2

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 "']?

4 Answers 4

5

You want the first element of the list without the first and last char

>>> l[0][1:-1]
'https://container.blob.core.windows.net/'
Sign up to request clarification or add additional context in comments.

1 Comment

Wow! The smallest amount of code possible. Nice! This worked as well.
2

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/

1 Comment

Thank you. I went with other solutions because the amount of code was less.
1

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.

Comments

1

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("'")

2 Comments

I went with your second option as it was the smallest amount of code. Edited a bit with: url = str(blob_url[0].strip('"')). Had to strip out the doublequote and convert to string. Thanks for your assistance!
@SeaDude glad it helps you somehow, Happy Coding!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.