DEV Community

Discussion on: Daily Challenge #304 - Consecutive Letters

Collapse
 
agtoever profile image
agtoever

Not too elegant, but a compact and efficient one-liner, using Python 3.8's assignment expressions.

solve = lambda s: (ord_list := list(map(ord, s))) and max(ord_list) - min(ord_list) == len(s) - 1

for case in ['abc', 'abd', 'dabc', 'abbc', 'v', 'zyx', 'azj']:
    print(f'{case}: {solve(case)}')
Enter fullscreen mode Exit fullscreen mode

Try it online!