2

I am attempting to create a list of all the combinations of strings from two separate lists. Here is my code:

class Function:
    all_prefixes = ['arc', 'inv', 'inverse']
    all_sin = ['sin', 'sine']
    all_asin = [x+y for x in all_prefixes for y in all_sin]

This generates:

Traceback (most recent call last):
  File "test", line 1, in <module>
    class Function:
  File "test", line 6, in Function
    all_asin = [x+y for x in all_prefixes for y in all_sin]
  File "test", line 6, in <listcomp>
    all_asin = [x+y for x in all_prefixes for y in all_sin]
NameError: name 'all_sin' is not defined

The same problem occurs when the code is moved into the initialiser instead of the variables being static. It does not occur when the code is not in the class. I do not have this problem when I run the code with Python 2.7.12. I am currently using Python 3.5.2. Help would be much appreciated because this is for a school project and I can't continue without figuring this one out. Thanks for the help.

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118

0 Answers0