-1

I am looking up a set of email addresses grouped together in a dictionary using the get() function

the get function returns

['[“one.yahoo.com”,”two.yahoo.com”,"three.yahoo.com"]']

I have tried several methods to remove the single quotes so that I end up with a list like this

email = [ [“one.yahoo.com”,”two.yahoo.com”,"three.yahoo.com"] ]

the dictionary looks like this

dict= { 'Warehouse':'[“x@yahoo.com”,”y@yahoo.com”,”z@yahoo.com”]', 'Bottling':'[“one.yahoo.com”,”two.yahoo.com”,"three.yahoo.com"]'}

timc
  • 1
  • 3

2 Answers2

1

Try this:

import ast # This contains a function to convert str to list
email = ['["one.yahoo.com", "two.yahoo.com", "three.yahoo.com"]']
email = str(email) # Converts to str type.
email = email.replace("'", "") # Replaces the apostrophes with blanks.
email = ast.literal_eval(email) # Converts to list. 
print(email)

Output is:

[["one.yahoo.com", "two.yahoo.com", "three.yahoo.com"]]
Ismail Hafeez
  • 730
  • 3
  • 10
0

You can try this:

email = ['["one.yahoo.com","two.yahoo.com","three.yahoo.com"]']

email = email[0].replace('"','')
email = email[1:-1].split(",")

Hope this may be of help.

jjoy
  • 162
  • 1
  • 10