Jump to content

Python: remove leading space from array of strings


Recommended Posts

Like most languages, Python has map().    I'm not sure this is actually better than iterating, given that ltrim is a built in string method:

 

strings = ['  hi', '    there', 'friend']
print(strings)
strings = list(map(lambda str: str.lstrip(), strings))
print(strings)

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.