Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Dictionnary brackets issue
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)
    for i in range(n):
        r= random.randint(a,b)
    for item in L:
        dict={str(item): "\""+str(0) +"\""}
    print("There are",(len(L)), "items")
    return L2
>>> fonction2_bis(5,1,2) There are 5 items [{'2': '"0"'}, {'2': '"0"'}, {'2': '"0"'}, {'2': '"0"'}, {'1': '"0"'}]
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.
newbieAuggie2019 likes this post
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Taking brackets out of list in print statement pythonprogrammer 3 310 Apr-13-2020, 12:25 PM
Last Post: perfringo
  printing a list contents without brackets in a print statement paracelx 1 234 Feb-15-2020, 02:15 AM
Last Post: Larz60+
  python dictionnary Omar_Yatim 3 385 Dec-08-2019, 05:12 AM
Last Post: scidam
  Access to the elements of a dictionnary Reims 1 328 Oct-02-2019, 12:48 PM
Last Post: SheeppOSU
  from Json Time Serie file to python dictionnary Reims 1 346 Sep-11-2019, 08:17 AM
Last Post: DeaD_EyE
  convert a json file to a python dictionnary of array Reims 2 372 Sep-10-2019, 01:08 PM
Last Post: Reims
  dictionnary lateublegende 1 524 Apr-29-2019, 09:10 PM
Last Post: Yoriz
  Why do we need setdefault() method for dictionnary? DJ_Qu 3 603 Apr-21-2019, 11:00 AM
Last Post: Gribouillis
  Json dictionnary on Redis katsu707 1 596 Dec-04-2018, 11:59 AM
Last Post: DeaD_EyE
  how to remove brackets within a list A3G 17 8,403 Oct-16-2016, 02:34 PM
Last Post: wavic

Forum Jump:

Users browsing this thread: 1 Guest(s)