On 18/03/2014 17:25, Filippo Dal Bosco - wrote:
Il giorno Tue, 18 Mar 2014 16:53:42 +0100
Marco Beri <marcob...@gmail.com> ha scritto:

2014-03-18 16:46 GMT+01:00 Filippo Dal Bosco - <
filippo.dalbo...@whiteready.com>:
[...]
 una lista che non contiene
' ', 'pippo' , 'pluto'

Allora vuoi che tutte e tre le condizioni siano soddisfatte allo stesso tempo: quindi un and.. per esempio

>>> l = [' ', 'pippo', 'pluto', 'peppa pig', 'mario', 'foo', 'homer']
>>> new_list = []
>>> for word in l:
        if word != ' ' and word != 'pippo' and word != 'pluto':
                print word, "oh yes!"
                new_list.append(word)
        else:
                print word, 'bye bye..'

                
  bye bye..
pippo bye bye..
pluto bye bye..
peppa pig oh yes!
mario oh yes!
foo oh yes!
homer oh yes!
>>> new_list
['peppa pig', 'mario', 'foo', 'homer']

Qualche altro esempio...
>>> word == 'pippo'
>>> word == ' ' or word == 'pippo' or word == 'pluto'
True
>>> word != ' ' or word != 'pippo' or word != 'pluto'
True
>>> word2 = 'mario'
>>> word2 == ' ' or word == 'pippo' or word == 'pluto'
True
>>> word2 == ' ' or word2 == 'pippo' or word2 == 'pluto'
False
>>> word2 != ' ' or word2 != 'pippo' or word2 != 'pluto'
True
>>> word2 != ' ' and word2 != 'pippo' and word2 != 'pluto'
True
>>> not word == ' ' or not word == 'pippo' or not word == 'pluto'
True
>>> not word2 == ' ' or not word2 == 'pippo' or not word2 == 'pluto'
True

Ciao
Lorenzo
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Reply via email to