1linePython
1.0.0
A collection of one-liner Python answers on some online code challenges.
The idea of this repository came when I challenged shinez1997 to resolve code problems on binarysearch.com with only one line of Python code. He is better than me in every aspect of coding, and this is only way I can beat him somehow.
return.Example:
# functools is imported by default
class Solution: # default by online judge
def minAddToMakeValid(self, s: str) -> int: # default by online judge
# answer fit in one line
return len(functools.reduce(lambda c1, c2: c2 if not c1 else c1[:-1] if c2==")" and c1[-1] == "(" else c1 + c2, s)) if s else len(s)Please use this template if you want to contribute to this list:
Source: Link
Description:
Description and example
Answer:
# Code in PythonExplanations: