All problems
Validate MAC Address
Problem
Return True if the string is a valid MAC address in either colon-separated or dash-separated form, and False otherwise.
A MAC address has exactly six groups of exactly two hexadecimal digits. Hex digits are 0 through 9 and a through f in either case.
Hint
Reject strings that use neither separator or that mix the two.
Test cases
case 1
in: ["00:1A:2B:3C:4D:5E"]
expected: true
case 2
in: ["00-1a-2b-3c-4d-5e"]
expected: true
case 3
in: ["00:1A:2B:3C:4D"]
expected: false
case 4
in: ["00:1G:2B:3C:4D:5E"]
expected: false
case 5
in: ["001A2B3C4D5E"]
expected: false
case 6
in: ["00:1A:2B:3C:4D:5E:6F"]
expected: false
Starter codePython
def valid_mac(s):
# Your code here
pass6 test cases · run your code against them in the editor