0

How to realize it in lambda function?

Examples: s=say_my_name -> sayMyName s1=all-you-need-is-love -> allYouNeedIsLove s2=The_truth_is_out_there -> TheTruthIsOutThere s3=hello -> hello #My attempts: #res = lambda s: ''.join([j[i+1] for i in range(len(s)-1) for j in s if j[i] == '_' or j[i]]) res = lambda s: ''.join([s[i+1].upper() for i in range(len(s)-1) if s[i] == '_' or s[i]]) print(res('say_no_more')) #why it doesn't work?can someone help, thanks:) ######another way###### I've solve it this way, but i need the lambda: import re p = [s[match.start()]+s[match.end()] for match in re.finditer('_', s)] # p >>> ['_m', '_n'] for c in p: if c in s: s = s.replace(c,c[1].upper()) print(s)

17th Oct 2020, 3:06 AM
Andrey Shintar
Andrey Shintar - avatar
2 Answers
+ 1
"The_truth_is_out_there" -> "TheTruthIsOutThere" For this one case, first word isn't converted to lowercase? shouldn't it be "theTruthIsOutThere"? https://code.sololearn.com/c95qNRd1h6aT/?ref=app
17th Oct 2020, 6:48 AM
Ipang
0
Almost good, but not: res = lambda s: ''.join([s[i+1].upper() if s[i] in ['_', '-'] else s[i] for i in range(len(s)) ])
17th Oct 2020, 4:21 AM
Andrey Shintar
Andrey Shintar - avatar