fork download
  1. def to_pascal_case(s):
  2. return ''.join(current.lower() if prev.isalnum() else current.upper()
  3. for prev, current in zip(' ' + s, s) if current.isalnum())
  4.  
  5.  
  6. test_data = ['', 'a', 'foo bar', 'PRODUCT_CHANGE_IT_LATER']
  7.  
  8. for s in test_data:
  9. print(s, to_pascal_case(s))
Success #stdin #stdout 0.01s 7168KB
stdin
Standard input is empty
stdout
('', '')
('a', 'A')
('foo bar', 'FooBar')
('PRODUCT_CHANGE_IT_LATER', 'ProductChangeItLater')