0
Extract the first word using a lambda function
Description of the task: Black Box (str -> str) Hello world => Hello a word => a don't touch it => don't greetings, friends => greetings ... and so on ... => and hi => hi ***We need to use just only a lambda function! My attempt: lambda s=' ..., first word': [((i*(i.isalpha()) or i) for i not in ' .,') for i in s.split()]
6 Answers
+ 2
Thanks, Valmob101, you are cool!
I've a little bit modified your function, and so, we've got it!)
The right answer is:
lambda s: str(''.join([i for i in s.split() if i[0].isalpha()][0])).split(',')[0]
+ 1
Use this:
c = ".,.,.. hello world"
a = (lambda x:[i for i in x if i[0].isalpha()][0])(c.split())
print(a)
+ 1
Valmob101, I've written the same yesterday
([i for i in s.split() if i.isalpha()==True][0])
, BUT
it doesn't pass words like "don't", or like "comma,". We need to except symbols , and '.
Take note of the description
+ 1
Andrex also try this:
https://code.sololearn.com/ce2eSWQwzv0M/?ref=app
0
>>>s= lambda x: x[:x.index(' ')]
>>>print(s('hello world'))
hello
0
Andrex , I fixed my answer(added [0] to i). Let me know whether this is what you want.