I'm trying to standardise the user input in this format: dddL
where d
is a digit and L
a capital letter. If the user doesn't add enough digits, I want to fill the missing digits with leading zeroes, if he adds anything else than at most 3 digits and a letter, just reject:
input/standardised example:
input: '1a'
output: '001A'
input: '0a'
output: '000A'
input: '05c'
output: '005C'
input: '001F'
output: '001F' (unchanged)
input: '10x'
output: '010X'
input: '110x'
output: '110X'
My broken attempt right now returns nothing for some reason: (doesn't yet deal with rejecting invalid input)
>>> x = ['0a', '05c', '001F', '10x']
>>> [i.upper() if len(i)==4 else ('0' * j) + i.upper() for j in range(4-len(i)) for i in x]
[]
I'm not looking necessarily for list processing, I only want it to work for a single variable as input