This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def partition(nums, condition): | |
""" | |
nums is ordered so that all the cases where condition is false at the beginning and it is true towards the end. | |
We are tryng to find the first index where the condition is true. | |
e.g | |
nums = [1, 1, 1, 1, 2] | |
condition = lambda val: val < 2 | |
partition will return 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def solution(formatString, replacements): | |
formatString = re.sub(r'([^{]){(\d+)}}', r'\g<1>{\g<2>}}}', formatString) | |
formatString = re.sub(r'{{(\d+)}([^}])', r'{{\g<1>}}\g<2>', formatString) | |
try: | |
return formatString.format(*replacements) | |
except ValueError: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class State: | |
def __init__(self, state): | |
self.state = state | |
def transistion(self, inp): | |
pass | |
class Start(State): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(template, replacements): | |
ans = '' | |
i = 0 | |
error = False | |
while i < len(template): | |
print(i) | |
if template[i] == '{': | |
if (i+1) < len(template) and template[i+1] == '{': | |
ans += '{' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(template, replacements): | |
ans = '' | |
i = 0 | |
iterator = TemplateIterator(template) | |
error = False | |
while template.hasnext(): | |
if is_literal_brace(template): | |
ans += '{' | |
template.advance(2) | |
elif is_in_brace(template): |
OlderNewer