Skip to content

Instantly share code, notes, and snippets.

@fbatroni
Created March 3, 2016 18:10
Show Gist options
  • Save fbatroni/97046d1e7a0bb2e45fe3 to your computer and use it in GitHub Desktop.
Save fbatroni/97046d1e7a0bb2e45fe3 to your computer and use it in GitHub Desktop.
#!/usr/bin/python

 # function that accepts 2 arrays. 
 # The arrays contain numbers and each input array is already sorted in increasing order. 
 # The function should create and return another array which contains all of the numbers that are in the 2 input arrays. 
 # The numbers in the returned array should also be sorted in increasing order
 # Example usage: python process_numbers.py [1,10,3,22,23,4,2,200,201,202,203,204,205,206,207,207,209] [5,8,9,11,25]
 
import sys


def process_numbers(arr1, arr2):
  combined = arr1 + arr2 
  return sorted(combined)

def main(argv):
  try:

    if len(argv) < 2 or len(argv) > 2:
      raise ValueError('Missing or wrong number of arguments')

    arr1 = eval(argv[0])
    arr2 = eval(argv[1])
    
    print process_numbers(arr1, arr2)
    
  except ValueError as e:
    print "error has occurred:: \n {0} \n args: {1}".format(e, argv)
    print 'USAGE: test.py <array1> <array2>'
    print 'NOTE: use comma-delimited arrays with no white space between numbers'
    sys.exit(2)

if __name__ == "__main__":
   main(sys.argv[1:])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment