Just playing with groupby:
PEP8 - Programming recommendations
So in conformance with PEP8 it should be expressed:
from itertools import groupby def pepify(_str): grouped = groupby(_str, lambda char: char.islower()) keep = lambda seq: ''.join(seq) change = lambda seq: ''.join(['_'] + [*seq]).lower() replaced = (change(seq) if case is False else keep(seq) for case, seq in grouped) return ''.join(replaced).lstrip('_') pepify('MyFunctionName') --> 'my_function_name'EDIT:
PEP8 - Programming recommendations
Quote:Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier
So in conformance with PEP8 it should be expressed:
from itertools import groupby def pepify(_str): grouped = groupby(_str, lambda char: char.islower()) def keep(seq): return ''.join(seq) def change(seq): return ''.join(['_'] + [*seq]).lower() replaced = (change(seq) if case is False else keep(seq) for case, seq in grouped) return ''.join(replaced).lstrip('_')
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.