0

I have currently a tuple of:

('(102,117,108)', '(108,32,116)', '(101,120,116)', '(32,105,115)', '(32,103,111)', '(111,100,32)')

How would I convert it to:

((102,117,108), (108,32,116), (101,120,116), (32,105,115), (32,103,111), (111,100,32))

Any help is much appreciated!

1 Answers1

2
>>> from ast import literal_eval
>>> t = ('(102,117,108)', '(108,32,116)', '(101,120,116)', '(32,105,115)', '(32,103,111)', '(111,100,32)')
>>> tuple(map(literal_eval, t))
((102, 117, 108), (108, 32, 116), (101, 120, 116), (32, 105, 115), (32, 103, 111), (111, 100, 32))

literal_eval(node_or_string)
Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, numbers, tuples, lists, dicts, booleans, and None.

timgeb
  • 76,762
  • 20
  • 123
  • 145