[Solved] How to convert this tuple to a dict in python


You need only the first element of the tuple. Split this element at the ': ' and you’ll get a list with the two parts you need.

data = ('"https://www.dzone.com": "Z"\n\n', '')[0].split(': ')

Now construct your dictionary by using strip to remove the unwanted characters at the beginning and end of each string.

result = {'URL': data[0].strip('"'), 'Rank': data[1].strip('"\n')}

solved How to convert this tuple to a dict in python