def CodelandUsernameValidation(s):
if len(s)>4 and len(s)<25 and s[0].isalpha() and [i for i in s if i.isalnum() or i=="_"]!=[] and s[-1]!="_":
return True
else:
return False
# keep this function call here
print(CodelandUsernameValidation(input()))
Tags:
它在
s
中生成字母数字或下划线字符的列表。该代码实际上是不正确的,因为如果任何字符是字母数字或下划线,它将通过,而其目的肯定是所有字符都必须是字母数字或下划线。这里有一个更好的写作方法:它是一个
list comprehension
如果您展开,它将如下所示->上述代码可重写为-
相关问题 更多 >
编程相关推荐