Created
July 17, 2020 08:30
-
-
Save aambrioso1/141ceda119af99dc6304b2cb595de4ec to your computer and use it in GitHub Desktop.
test_6.py
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 reverse_lst(lst): | |
ans = [] | |
for i in range(len(lst)-1, -1, -1): | |
ans.append(lst[i]) | |
return ans | |
def add_one(lst): | |
lst = reverse_lst(lst) | |
for n , ele in enumerate(lst): | |
if ele == 0: | |
lst[n] = 1 | |
return reverse_lst(lst) | |
else: | |
lst[n] = 0 | |
print(lst) | |
return reverse_lst(lst) | |
def comp_lst(lst): | |
new_lst = [] | |
for i, ele in enumerate(lst): | |
print(lst,(i, ele)) | |
if ele == 0: | |
new_lst.append(1) | |
else: | |
new_lst.append(0) | |
return new_lst | |
def neg_bin(lst): | |
lst = comp_lst(lst) | |
lst = add_one(lst) | |
return lst | |
print('answer =',neg_bin([1,1,1,0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment