Created
September 14, 2015 18:10
-
-
Save mylons/fd852d2b7246f75cd7f2 to your computer and use it in GitHub Desktop.
run time interview questions
This file contains 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
# assume inputs are lists | |
def merge1(words, more): | |
sentence = "" | |
for w in words: sentence += w | |
for w in more: sentence += w | |
return sentence | |
def merge2(words, more): | |
sentence = [] | |
for w in words: sentence.append(w) | |
for w in more: sentence.append(w) | |
return sentence |
haha, something about concatenating strings in python? maybe a string is actually just a list in python and you're getting the auto-expanding behavior?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, merge1 is actually faster contrary to our assumptions.