0
first='4x2'
second='9x'
self.first = [i + ' ' for i in first]
self.second = [i + ' ' for i in second]    
self.poly = list(chain(self.first, self.second))
if self.poly[1].lower() is 'x' and self.poly[4].lower() is 'x':
    >> Fails here

but if i have an array like:

array = ['x']
if array[0] is 'x':

it passes?

DjaouadNM
  • 22,013
  • 4
  • 33
  • 55

1 Answers1

1

Use == for comparing strings, and also remove extra spaces, just in case:

if self.poly[1].strip().lower() == 'x' and self.poly[4].strip().lower() == 'x':
Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • @beaglecode It fails because your strings `self.poly[1]` and `self.poly[4]` have a space in them, so they would pass comparison with `'x '`. You _do_ need to use the `==` however. – nielsen Sep 03 '19 at 16:10
  • @ beaglecode As nielsen said, you might have spaces in the string, better to remove them. I updated my answer. – Óscar López Sep 03 '19 at 16:33