eliminate selected column of elements from a list of lists -


i have list of lists each individual list has 3 elements. this:

[[928.7, 554.29999958311, 0],  [928.7, 558.15990063549, 0],  [914.1, 558.15990063549, 0],  [914.1, 554.29999958311, 0]] 

how can delete elements particular column? example if input "1" delete first column, if input "2" delete second 1 , on.

i assume question regards pyhton...

i try following (using numpy):

    import numpy np      initial_list = [[928.7, 554.29999958311, 0],                      [928.7, 558.15990063549, 0],                      [914.1, 558.15990063549, 0],                      [914.1, 554.29999958311, 0]]      # transform list in numpy array     = np.array(initial_list)      # remove column want , put output in new variable     a1 = np.delete(a, 0, 1) # remove first column(0)                             #+the second "1" in arguments tells                              #+numpy delete column instead of                             #+ row.      # convert plain list     final_list = a1.tolist() 

if want stay plain python, suggest like:

    initial_list = [[928.7, 554.29999958311, 0],                      [928.7, 558.15990063549, 0],                      [914.1, 558.15990063549, 0],                      [914.1, 554.29999958311, 0]]      row in initial_list:         del row[0]  # delete first column matrix       final_list = initial_list 

pay attention fact latter method "overwrite" original list , loose deleted data. consider, if need, create copy of initial_list:

    initial_list_bck[:] = initial_list[:]     # or     initial_list_bck = initial_list.copy()     # following create pointer first list     initial_list_bck = initial_list 

hope helpful.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -