How do you remove brackets and quotes from a list in Python?

 There are various methods to remove brackets and quotes from a list in python.

Using * operator

The * administrator in Python can be utilized to unload objects. It unloads every one of the components from a rundown and prints it without the square brackets and quotation as displayed underneath.

list = ['shubham','anurag','ankit','pravin']

print(*lst, sep = ',')

Output:

shubham,anurag,ankit,pravin

We separate the elements using the character specified in the sep parameter and can be removed if desired.

Using str function

Steps:

  1. In this method, we convert a list to a string using the str() function
  2. then remove the first and last characters from this string that are the square brackets and quotes.

list = [1,2,3,4,5,6,8,9]

list_str = str(list)[1:-1]

print(list_str)

Output:

1, 2, 3, 4, 5, 6, 8, 9

 

 

 

Comments

Popular posts from this blog

proassignment help backlink data index 41

programming shark backink data index 31

Programming shark backlink data index 67