Search code examples
pythondictionaryformattingf-string

How can I do a dictionary format with f-string in Python


my code is as below

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = f'{"siteUrls": {aaa}}'
print(REQUEST)

I've tried

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = {"siteUrls": {}}.format(aaa)
print(REQUEST)

and

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = {"siteUrls": %s}%aaa
print(REQUEST)

all of them didn't work
REQUEST must be dict.
please help.


Solution

  • try this

    aaa = "['https://google.com', 'https://yahoo.com']"
    REQUEST = {"siteUrls": f"{aaa}"}
    print(REQUEST)