0

I have a nested list that I would like to delete rows after it has finished with them. i tried using enumerating to pass in the index of the row to delete.

nlist = [['Chris', 'Davids', 21], ['Rob', 'Croft', 26]]

for i, v in enumerate(nlist):
   if v[0] == 'Chris':
       del v[i]
Mantis
  • 1,357
  • 3
  • 27
  • 49

1 Answers1

1

== 'chris' should be == 'Chris': because 'chris' will never be true because all your names start with a capital letter

This will remove the whole first sublist:

nlist = [['Chris', 'Davids', 21], ['Rob', 'Croft', 26]]

for i, v in enumerate(nlist):
   if v[0] == 'Chris':
       nlist.remove(nlist[i])

print nlist
heinst
  • 8,520
  • 7
  • 41
  • 77
  • That was a typo in the post. I edit the original when i realized. Thanks for your answer. Just what i was looking for. – Mantis Aug 03 '15 at 13:08