-2

I am doing a mini project and i have encountered the problem suggested in title. Below is a example:

list = ["bird", "deer", "dog", "bat"]
list -= "bird"
print list

and the error says:

TypeError: unsupported operand type(s) for -=: 'list' and 'str'

This seemed like an omnipresent questions so i searched it up but couldn't found the relevant answer, very sorry if this question is repeative to others on this site. Help will be greatly appreciated!

Ren
  • 2,852
  • 2
  • 23
  • 45
pythonsohard
  • 127
  • 9

2 Answers2

1

Use list.remove()

For example:

example_lst = [123, 'xyz', 'zara', 'abc', 'xyz']; 
example_lst.remove('xyz');
print "List : ", example_lst
example_lst.remove('abc');
print "List : ", example_lst

Output:

List :  [123, 'zara', 'abc', 'xyz']
List :  [123, 'zara', 'xyz']

The example above is taken from tutorialspoint.com

Ofir
  • 5,049
  • 5
  • 36
  • 61
1

You can use remove:

list.remove("bird")
Olegp
  • 182
  • 2
  • 14