1

I have a Python list (mixed with string and values) like below:

mylist = [('Needie', 83, 55, 78, None), ('Blue', 80, 60, None, 66), ('Bloodnok', None, 54, 57, 59), (None,)]

The desired output should be:

newlist = [('Needie', 83, 55, 78, None), ('Blue', 80, 60, None, 66), ('Bloodnok', None, 54, 57, 59)]

What should I do to remove the last tuple (None,) in the list? Keep other tuples as before, includes names (string), None value and floats

del list[:-1]

Output:

[(None,)]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jim Ye
  • 77
  • 8
  • 4
    `del list[-1]` should do it (changes the existing list), as would `newlist = list[:-1]` (assigns a changed copy to `newlist` and leaves `list` intact). – Zinki Apr 27 '18 at 13:22
  • ahhhh, that's why. Thanks Zinki. – Jim Ye Apr 27 '18 at 13:33

0 Answers0