lambda requirements

Wolfgang Thaemelt wolfgang.thaemelt at orsoft.de
Mon Jul 3 08:41:26 EDT 2000


Running the script:

#----------------------------------------- begin of script
def SymmetricDifference(list1, list2):
#      global _list1
#      global _list2

      _list1 = list1
      _list2 = list2

      _onlylist1 = filter(lambda x: x not in _list2, _list1)

      return _onlylist1

if __name__ == '__main__':
  a = [1,2,3,4,5]
  b = [3,4,5,6,7]
  x = SymmetricDifference(a,b)

  print x
#---------------------------------------- end of script

gives the error:

Traceback (innermost last):
  File "E:\up\000701\symmdiff.py", line 16, in ?
    x = SymmetricDifference(a,b)
  File "E:\up\000701\symmdiff.py", line 9, in SymmetricDifference
    _onlylist1 = filter(lambda x: x not in _list2, _list1)
  File "E:\up\000701\symmdiff.py", line 9, in <lambda>
    _onlylist1 = filter(lambda x: x not in _list2, _list1)
NameError: _list2

If the comment characters "#"  are removed from the "global" statements
everything works fine.

Is there some requirement on a lambda violated in the script?


Thanks

Wolfgang Thaemelt


OR Soft Jaenicke GmbH
Geusaer Str., FH Geb. 106
06217 Merseburg
Germany
======================================
Email: wolfgang.thaemelt at orsoft.de
Voice: +49-3461-549033
Fax:   +49-3461-549022





More information about the Python-list mailing list