Dictionnary brackets issue - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Dictionnary brackets issue (/thread-22382.html) |
Dictionnary brackets issue - Reldaing - Nov-10-2019 Hi, little issue. Could u please tell me how to remove the {} between each number and "0" in the output of the console ? Thanks! def fonction2_bis(n,a,b): import random r= random.randint(a,b) L=[] L2=[] for i in range(n): r= random.randint(a,b) L.append(r) for item in L: dict={str(item): "\""+str(0) +"\""} L2.append(dict) print("There are",(len(L)), "items") return L2
RE: Dictionnary brackets issue - ichabod801 - Nov-10-2019 You can't. That's the return value. The return value is a list of dictionaries. That's what a list of dictionaries looks like. If you want to print that return value in a way that does not have those brackets, you can do that. But you would need to to loop through the values in that list, constructing a string representation of the list that did not have those brackets. Something like print(', '.join(str(data)[1:-1] for data in return_value)) would do that.
|