gw1500se Posted June 23, 2019 Share Posted June 23, 2019 It there a way, without a loop, to remove the leading whitespace from each element of an array of strings? TIA. Quote Link to comment https://forums.phpfreaks.com/topic/308878-python-remove-leading-space-from-array-of-strings/ Share on other sites More sharing options...
gizmola Posted June 24, 2019 Share Posted June 24, 2019 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) Quote Link to comment https://forums.phpfreaks.com/topic/308878-python-remove-leading-space-from-array-of-strings/#findComment-1567855 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.