[英]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.