python numpy parse array to get items
Question: Hi I tried taking distinct items of every sublist and making an array

My input is a 2D list

    
    
     alist =  [['1','2'], ['3','5','2'], ['15','1'], ['5','657','3','1']]
    

And output I want is an array of distinct items

    
    
      out = [1,2,3,5,15,657]
    

I tried

    
    
     from numpy import np
    
     alist =  [['1','2'], ['3','5','2'], ['15','1'], ['5','657','3','1']]
     anarray = np.array(alist)
     newarray = []
     for i in anarray:
          for j in i:
               if j in newarray:
                    pass
               else:
                    print j
    


Answer: 
    from itertools import chain
    
    alist = [['1', '2'], ['3', '5', '2'], ['15', '1'], ['5', '657', '3', '1']]
    
    # Flatten the list into a single-level list of all the values
    flattened_list = list(chain.from_iterable(alist))
    
    # Use a set to remove the duplicates
    uniques = set(flattened_list)
    
    # Sort the unique values by the numeric value of each value
    sorted_results = sorted(uniques, key=lambda value: int(value))
    
    print sorted_results
    

