Skip to content

Instantly share code, notes, and snippets.

@internetsadboy
Created November 5, 2014 23:36
Show Gist options
  • Select an option

  • Save internetsadboy/ac2f5fc8e56710ddedb5 to your computer and use it in GitHub Desktop.

Select an option

Save internetsadboy/ac2f5fc8e56710ddedb5 to your computer and use it in GitHub Desktop.
Project X: concat.py
"""
Jared Halpert
11/5/14
concat
Concatenate two lists of elements composed of any data type
into one list of elements composed of any data type
@param {list} a list of elements
@param {list} b list of elements
@return {list} c concatenation of lists a and b
"""
def concat(a, b):
# compute the length of a
na = len(a)
# compute the length of b
nb = len(b)
# compute the length of c
cn = na + nb
# the concatenated list
c = range(cn)
# copy contents of the first list
for i in range(na):
c[i] = a[i]
# copy contents of the second list
for j in range(nb):
c[na + j] = b[j]
# return the concatenated list
return c
# test that concat returns the expected result
assert (concat([1,2,3], [4,5,6]) == [1,2,3,4,5,6])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment