[英]determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array
[英]Determine whether there’s more than one word in a string
例如:
line = 'how are you?'
if line == [has more than one word]: line.split()
这可能吗?
尝试这个:
line = 'how are you?'
if len(line.split()) > 1: # has more than 1 word
获得line.split()似乎更pythonic,但如果这将是一个昂贵的操作,这可能会更快:
if ' ' in 'how are you?': line.split()
line.strip().count(' ') > 0 # finds at least one separator after removing the spaces at the left and the right of the actual string
或者如果你真的想要速度
line.strip().find(' ') != -1 # not finding the ' ' character in the string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.