Created
September 6, 2016 01:37
-
-
Save ooade/40d0174811c2d758f1adec4aa371c24a to your computer and use it in GitHub Desktop.
Replicate
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 replicate_recur(times, data): | |
try: | |
if type(data) is not(int) and type(data) is not(str): | |
raise ValueError("Wrong Input Found!") | |
arr = [] | |
def recur(times, data): | |
if times <= 0: | |
return arr | |
else: | |
arr.append(data) | |
return recur(times - 1, data) | |
return recur(times, data) | |
except(AttributeError,TypeError): | |
raise ValueError("Wrong Input Found!") | |
def replicate_iter(times, data): | |
try: | |
if type(data) is not(int) and type(data) is not(str): | |
raise ValueError("Wrong Input Found!") | |
arr = []; | |
if times < 0: | |
return arr | |
for i in range(times): | |
arr.append(data) | |
return arr | |
except(AttributeError,TypeError): | |
raise ValueError("Wrong Input Found!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment