Answers for "remove spaces from a list python"

1

remove spaces from a list python

for i in range(0,(len(list))):
        x = str(list[i]).strip(' ')
        list[i] = x
Posted by: Guest on April-24-2022
5

remove spaces from string python

s = '  Hello   World     From  Pankaj  \t\n\r\t  Hi       There        '

>>> s.replace(" ", "")
'HelloWorldFromPankaj\t\n\r\tHiThere'
Posted by: Guest on August-27-2020
1

remove spaces in string python

words = "   test     words    "

# Remove end spaces
def remove_end_spaces(string):
    return "".join(string.rstrip())

# Remove first and  end spaces
def remove_first_end_spaces(string):
    return "".join(string.rstrip().lstrip())

# Remove all spaces
def remove_all_spaces(string):
    return "".join(string.split())

# Remove all extra spaces
def remove_all_extra_spaces(string):
    return " ".join(string.split())

# Show results
print(f'"{words}"')
print(f'"{remove_end_spaces(words)}"')
print(f'"{remove_first_end_spaces(words)}"')
print(f'"{remove_all_spaces(words)}"')
print(f'"{remove_all_extra_spaces(words)}"')
Posted by: Guest on October-13-2021

Code answers related to "remove spaces from a list python"

Python Answers by Framework

Browse Popular Code Answers by Language