You are viewing a single comment's thread. Return to all comments →
I used groupby from itertools since I wasnt able to form regex for second pattern here
import re from itertools import groupby pat = r'^[456]\d{3}(-?\d{4}){3}$' for _ in range(int(input())): flag = True inp = input() if re.fullmatch(pat, inp): inp = inp.replace('-','') grp = groupby(inp) for k, g in grp: if len(list(g))>=4: flag = False break else: flag=False if flag: print("Valid") else: print("Invalid")
Seems like cookies are disabled on this browser, please enable them to open this website
Validating Credit Card Numbers
You are viewing a single comment's thread. Return to all comments →
I used groupby from itertools since I wasnt able to form regex for second pattern here