-4

I've been looking for a way to split by ',' in a dictionary while retaining the present lists but have not been succesful. I want to split this dictionary:

{'R_ARABR': ['YHR104W'], 'R_GLYCt': ['YLL043W'], 'R_LPP_SC': ['YDR284C', 'YDR503C'], 'R_TREH': ['YDR001C', 'YBR001C'], 'R_CTPS2': ['YBL039C', 'YJR103W'], 'R_CTPS1': ['YBL039C', 'YJR103W']}

To appear like this:

{'R_ARABR': ['YHR104W'],
'R_GLYCt': ['YLL043W'],
'R_LPP_SC': ['YDR284C', 'YDR503C'],
'R_TREH': ['YDR001C', 'YBR001C'],
'R_CTPS2': ['YBL039C', 'YJR103W'],
'R_CTPS1': ['YBL039C', 'YJR103W']}

Help is much appreciated!

Cheeseburgler
  • 31
  • 1
  • 4

1 Answers1

3

You can use pprint.pprint, eg:

>>> import pprint
>>> d = {'R_ARABR': ['YHR104W'], 'R_GLYCt': ['YLL043W'], 'R_LPP_SC': ['YDR284C', 'YDR503C'], 'R_TREH': ['YDR001C', 'YBR001C'], 'R_CTPS2': ['YBL039C', 'YJR103W'], 'R_CTPS1': ['YBL039C', 'YJR103W']}
>>> pprint.pprint(d)
{'R_ARABR': ['YHR104W'],
 'R_CTPS1': ['YBL039C', 'YJR103W'],
 'R_CTPS2': ['YBL039C', 'YJR103W'],
 'R_GLYCt': ['YLL043W'],
 'R_LPP_SC': ['YDR284C', 'YDR503C'],
 'R_TREH': ['YDR001C', 'YBR001C']}

If you want to get the result as a string to then use elsewhere (maybe write to a file), then use pprint.pformat as pprint.pprint writes directly to stdout and returns None.

Jon Clements
  • 138,671
  • 33
  • 247
  • 280