About
Kodeclik is an online coding academy for kids and teens to learn real world programming. Kids are introduced to coding in a fun and exciting way and are challeged to higher levels with engaging, high quality content.
Popular Classes
Scratch Coding
Minecraft Coding
TinkerCAD
Roblox Studio
Python for Kids
Javascript for Kids
Pre-Algebra
Geometry for Kids
Copyright @ Kodeclik 2025. All rights reserved.
Sometimes when you are dabbling with Python lists, you might wish to print a list without the annoying brackets and commas that Python by default prints. For instance, consider the following code:
The output is:
Let us figure out how to get rid of the (square) brackets, commas, and even the quotes if you need so! There are at least four different ways to do so!
The first approach is to use the print function, like above, but with a “sep” argument specifying the separator (in our case, we do not wish for any separator):
The output will be:
as desired.
In our second approach, we use the map function to convert all arguments to strings and then use the join function to concatenate them giving the empty string as the starting point for the join function:
The output is again:
This approach is a bit traditional but illustrates how we can use a for loop with an end argument to achieve the same effect:
The output is:
Note that with this approach we do not print a newline at the end of all the printing: the cursor will be positioned just after the “r” in our string.
The translate method allows you to make modifications to a string, where some specified characters are replaced with the character described in a dictionary, or in a mapping table. For this purpose, we first create a dictionary and then use this dictionary in the translate() method:
Here the codes 32, 39, 44, 91, and 93 refer to the characters for space, starting and closing brackets, left square bracket, and right square bracket respectively. All these characters are mapped to ‘None’ in the dictionary which is then used in the translate method. The output is as before:
You have learnt four different ways to “sanitize” a list by removing brackets, commas, and spaces before printing it. Which one is your favorite?
If you liked the list manipulations here, checkout our companion blogpost on how to split a Python list into sublits of different, specified, sizes!
For more Python content, checkout the math.ceil() and math.floor() functions! Also
learn about the math domain error in Python and how to fix it!
Interested in more things Python? Checkout our post on Python queues. Also see our blogpost on Python's enumerate() capability. Also if you like Python+math content, see our blogpost on Magic Squares. Finally, master the Python print function!
Want to learn Python with us? Sign up for 1:1 or small group classes.
mylist = ['Jan',1,2023,'Happy','New','Year']
print(mylist)
['Jan', 1, 2023, 'Happy', 'New', 'Year']
mylist = ['Jan',1,2023,'Happy','New','Year']
print(*mylist,sep='')
Jan12023HappyNewYear
mylist = ['Jan',1,2023,'Happy','New','Year']
print (''.join(map(str, mylist)))
Jan12023HappyNewYear
mylist = ['Jan',1,2023,'Happy','New','Year']
for i in mylist:
print(i,end='')
Jan12023HappyNewYear
mylist = ['Jan',1,2023,'Happy','New','Year']
mydict = {32: None, 39: None, 44: None, 91: None, 93: None}
print(str(mylist).translate(mydict))
Jan12023HappyNewYear