0
str_arr = input()
    d = "}, "

    for line in str_arr:
        new_str = [e + '},' for e in str_arr.split(d) if e]

    print(len(new_str))
    for i in new_str:
        print(i)

I want my code to accept a list of dictionaries but the input is a string and tried to make the input str_list to a list but my code adds }, at the end of the console output how can I remove it.enter image description here

Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53
Owen Alikula
  • 408
  • 3
  • 11

1 Answers1

1

In the for loop, should you simply do:

new_str = [eval(e.strip()) for e in str_arr.split(",")]

I assume that str_arr is an input like {"A":1},{"B":2,"C":3}, in other words, a string of comma separated dictionaries

nikeros
  • 3,302
  • 2
  • 10
  • 26