python - Get the number of character classes from an argument -
the program takes single string command line argument. should print out number of character classes contained in string, e.g. abn1
.
import sys = sys.argv[1] if a.upper(): = 1 elif a.lower(): = + 1 elif a.digit(): = + 1 else: = + 1
i use loop include 4 character classes: digits, lower case characters, upper case characters , special characters, i.e. else.
following zondo's answer, came with:
import sys s = sys.argv[1] methods = {str.isdigit: 'd', str.isupper: 'u', str.islower: 'l', (lambda c: (not str.isdigit(c) , not str.isupper(c) , not str.islower(c))):'s'} result = set() c in s: m in methods: if m(c): result.add(methods[m]) print(len(result))
Comments
Post a Comment