Python Forum
how to remove brackets within a list
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to remove brackets within a list
#1
Hello,

I would like to know how to get rid of brackets within a list. Ex. ['1', 'r', (2, '5')]. The round brackets inside this list, I would like to get rid of. 

Here is the code in question:

#function for requesting numerical mark --> ask if this function is necessary because computeGrade prompts for both the mark and gives the letter grade.
def getMark():
    mark = int(input("What is your mark? (eg. 50) "))
    return mark


#function for letter grades
def computeGrade():
    #must get the grade from function getMark() or it will keep asking you for inputs each step of the way, when entering getMark in as a function
    gr = getMark()
    if gr < 50:
        g = "F"
        print(g)
    elif gr > 49 and gr < 55:
        g = "D"
        print(g)
    elif gr > 54 and gr < 65:
        g = "C"
        print(g)
    elif gr > 64 and gr < 80:
        g = "B"
        print(g)
    elif gr >= 80:
        g = "A"
        print(g)
    else: #how to make it so if they enter anything other than numerical values it gives you an error message?
        print("Invalid input, please enter your numerical grade such as 40, 80, or 90")
    return(gr, g)
        
#making the list using previous functions        
def student():
    #studlist = [getLastname(), getFirstname(), getMark(), computeGrade()]
    studlist = [getLastname(), getFirstname(), computeGrade()]
    return studlist

print(student())
I would like to eventually get this to print off an index with no brackets what so ever. But I have seen a tutorial on how to do that in the "list basic" thread. Unfortunately, the procedure will print with the round brackets included for the above code.

Look forward to your responses.

Thank you,
A3G
Reply


Messages In This Thread
how to remove brackets within a list - by A3G - Oct-16-2016, 10:39 AM
RE: how to remove brackets within a list - by wavic - Oct-16-2016, 11:00 AM
RE: how to remove brackets within a list - by Yoriz - Oct-16-2016, 11:05 AM
RE: how to remove brackets within a list - by wavic - Oct-16-2016, 11:10 AM
RE: how to remove brackets within a list - by Yoriz - Oct-16-2016, 11:16 AM
RE: how to remove brackets within a list - by A3G - Oct-16-2016, 11:20 AM
RE: how to remove brackets within a list - by wavic - Oct-16-2016, 11:25 AM
RE: how to remove brackets within a list - by A3G - Oct-16-2016, 11:31 AM
RE: how to remove brackets within a list - by Yoriz - Oct-16-2016, 11:31 AM
RE: how to remove brackets within a list - by A3G - Oct-16-2016, 11:39 AM
RE: how to remove brackets within a list - by Yoriz - Oct-16-2016, 11:44 AM
RE: how to remove brackets within a list - by wavic - Oct-16-2016, 11:44 AM
RE: how to remove brackets within a list - by A3G - Oct-16-2016, 12:16 PM
RE: how to remove brackets within a list - by Yoriz - Oct-16-2016, 12:42 PM
RE: how to remove brackets within a list - by A3G - Oct-16-2016, 01:11 PM
RE: how to remove brackets within a list - by Yoriz - Oct-16-2016, 01:24 PM
RE: how to remove brackets within a list - by A3G - Oct-16-2016, 01:39 PM
RE: how to remove brackets within a list - by wavic - Oct-16-2016, 02:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to remove all elements from list based on a condition sg_python 3 483 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Remove numbers from a list menator01 4 1,375 Nov-13-2022, 01:27 AM
Last Post: menator01
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into &lt;/&gt;? Winfried 0 1,551 Sep-03-2022, 11:21 PM
Last Post: Winfried
  Reading list items without brackets and quotes jesse68 6 4,691 Jan-14-2022, 07:07 PM
Last Post: jesse68
  Remove empty keys in a python list python_student 7 3,105 Jan-12-2022, 10:23 PM
Last Post: python_student
  Data pulled from SQL comes in brackets nickzsche 3 2,714 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,324 Dec-28-2021, 11:32 AM
Last Post: new_coder_231013
  Remove an item from a list contained in another item in python CompleteNewb 19 5,853 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Getting a certain value from inside brackets. LeoT 5 3,066 Mar-01-2021, 03:34 PM
Last Post: buran
  .remove() from a list - request for explanation InputOutput007 3 2,279 Jan-28-2021, 04:21 PM
Last Post: InputOutput007

Forum Jump:

User Panel Messages

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