-3

again, I would need help and specifically with two things

im search for all this number , curetly resoluts

the first is how to make to this input

{51, {'B', 'YZ', 'Y', 'Z', 'ZY', 'A', 'X', 'W'}}

this and after the number , I change the comma to: this output im search

{51: {'B', 'YZ', 'Y', 'Z', 'ZY', 'A', 'X', 'W'}}

the result is always more so that it works even with more fields

{2, {'AA', 'Z', 'B', 'A'}, 3, {'B', 'D', 'C', 'AB', 'Z', 'Y', 'BA ', 'A'}, 4, {'E', 'B', 'D', 'C', 'F', 'BB', 'Z', 'X', 'Y', 'AC', 'A', 'CA'}, 5, {'DA', 'BC', 'E', 'W', 'CB', 'B', 'D', 'G', 'AD', 'C ', 'H', 'F', 'Z', 'X', 'Y', 'A'}}
Ion Secred
  • 11
  • 6

1 Answers1

1

I think this is what you want. Let me know.

input_str = r"{2, {'AA', 'Z', 'B', 'A'}, 3, {'B', 'D', 'C', 'AB', 'Z', 'Y', 'BA ', 'A'}, 4, {'E', 'B', 'D', 'C', 'F', 'BB', 'Z', 'X', 'Y', 'AC', 'A', 'CA'}, 5, {'DA', 'BC', 'E', 'W', 'CB', 'B', 'D', 'G', 'AD', 'C ', 'H', 'F', 'Z', 'X', 'Y', 'A'}}"
output = input_str.replace(", {", ": {")
print(output)

Output:

{2: {'AA', 'Z', 'B', 'A'}, 3: {'B', 'D', 'C', 'AB', 'Z', 'Y', 'BA ', 'A'}, 4: {'E', 'B', 'D', 'C', 'F', 'BB', 'Z', 'X', 'Y', 'AC', 'A', 'CA'}, 5: {'DA', 'BC', 'E', 'W', 'CB', 'B', 'D', 'G', 'AD', 'C ', 'H', 'F', 'Z', 'X', 'Y', 'A'}}

See https://docs.python.org/3/library/stdtypes.html#str.replace

GordonAitchJay
  • 4,640
  • 1
  • 14
  • 16