I have a file (list) I want to search the list for a match element in the first position [0] - lets say search for the number 2 and if it matches extract the row to a new list - there are six 2's in the first position so i would want to extract all 6 rows.
pl = ['1 325 160 2.0\n', '1 600 100 6.2\n', '2 325 220 1.0\n', '3 600 200 4.4\n', '4 325 100 3.0\n', '4 325 88 3.2\n', '2 600 200 3.3\n', '2 325 100 3.3\n', '4 600 210 3.4\n', '5 325 105 3.5\n', '1 600 110 6.0\n', '3 325 100 3.1\n', '2 600 120 5.5\n', '2 600 125 5.5\n', '5 120 60 2.2\n', '2 325 100 3.4']
Thank you
You can just filter the list based on your condition:
result = [row for row in pl if row[0] == '2']
This outputs:
['2 325 220 1.0\n', '2 600 200 3.3\n', '2 325 100 3.3\n', '2 600 120 5.5\n', '2 600 125 5.5\n', '2 325 100 3.4']