suggestions for VIN parsing
Rick Johnson
rantingrickjohnson at gmail.com
Mon Dec 29 02:08:14 EST 2014
On Monday, December 29, 2014 12:50:39 AM UTC-6, Rick Johnson wrote:
[EDIT]
> 3. Now you can write some fairly simple logic.
>
> prog = re.compile("pat1|pat2|pat3...")
> def parse_vin(vin):
> match = prog.search(vin)
> if match:
> gname = # Fetch the groupname from the match object.
> number = # Fetch the digits from the group capture.
> d = database[gname]
> for k in d:
> low, high = d[k]
Dammit! That last line should have been:
low, high = k
But even better would be:
d = database[gname]
for low,high in d:
if low <= number <= high:
...
I knew something was tickling my sub-conscience as i sent
that reply, i should have known better!
PS: Hey, I said it was "fairly simple" logic, not "perfect"
logic!
More information about the Python-list
mailing list