I'm trying to print the usernames that contain only letters, numbers, "-" and "_" and are between 3 and 16 characters long.
usernames = input().split(', ')
for word in usernames:
if 3 <= len(word) <= 16 and (c for c in word if (c.isalnum() or c == '_' or c == '-')) and ' ' not in word:
print(word)
Input:
Jeff, john45, ab, cd, peter-ivanov, @smith
Output must be:
Jeff
John45
peter-ivanov
But instead is:
Jeff
john45
peter-ivanov
@smith
Why is that so?