Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionnary brackets issue
#1
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
Output:
>>> fonction2_bis(5,1,2) There are 5 items [{'2': '"0"'}, {'2': '"0"'}, {'2': '"0"'}, {'2': '"0"'}, {'1': '"0"'}]
Reply


Messages In This Thread
Dictionnary brackets issue - by Reldaing - Nov-10-2019, 10:38 PM
RE: Dictionnary brackets issue - by ichabod801 - Nov-10-2019, 11:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into </>? Winfried 0 1,535 Sep-03-2022, 11:21 PM
Last Post: Winfried
  Reading list items without brackets and quotes jesse68 6 4,649 Jan-14-2022, 07:07 PM
Last Post: jesse68
  Data pulled from SQL comes in brackets nickzsche 3 2,681 Jan-04-2022, 03:39 PM
Last Post: ibreeden
  For Loop and Use of Brackets to Modify Dictionary in Tic-Tac-Toe Game new_coder_231013 7 2,274 Dec-28-2021, 11:32 AM
Last Post: new_coder_231013
  Dictionnary indexing error Ander 6 1,887 Sep-10-2021, 12:22 PM
Last Post: Ander
  Getting a certain value from inside brackets. LeoT 5 3,035 Mar-01-2021, 03:34 PM
Last Post: buran
  Removing internal brackets from a string Astrikor 4 2,688 Jun-04-2020, 07:54 PM
Last Post: Astrikor
  Taking brackets out of list in print statement pythonprogrammer 3 2,416 Apr-13-2020, 12:25 PM
Last Post: perfringo
  printing a list contents without brackets in a print statement paracelx 1 2,142 Feb-15-2020, 02:15 AM
Last Post: Larz60+
  python dictionnary Omar_Yatim 3 2,841 Dec-08-2019, 05:12 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020