Home > Back-end >  Formatting print statement to show elements of a list
Formatting print statement to show elements of a list

Time:03-23

Hi I am having trouble making my print statement look how I want it to, this is causing my assignment to fail on an autograder. currently my code responsible for outputting the final statement looks like

    retStr = []
    for candidate in eliminated:
        retStr.append(candidate) # = candidate   ", "
    # e_order = ""
    # for x in range(len(retStr)):
    #     e_order = e_order   x

    print("Elimination order: ", retStr)
main()

and the final output looks like Elimination order: ['3', '5', '4', '2', '1']

how do I make it so that the final output looks like Elimination order: 3, 5, 4, 2, 1

exactly and no comma at the end or anything it needs the spaces and needs to look exactly like that

I would really appreciate if someone could help me out with this :)

CodePudding user response:

You can try below solution by converting list into string and then appending it to print statement:.

print("Elimination order:", ', '.join(retStr))

CodePudding user response:

print "Elimination order:", str(retStr)[1:-1]
  • Related