Skip to content

Instantly share code, notes, and snippets.

@ooade
Created September 6, 2016 01:37
Show Gist options
  • Save ooade/40d0174811c2d758f1adec4aa371c24a to your computer and use it in GitHub Desktop.
Save ooade/40d0174811c2d758f1adec4aa371c24a to your computer and use it in GitHub Desktop.
Replicate
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