what am I missing (syntax error)

O

orangeDinosaur

Here's a section of code:

for x in occupants:
if x not in uniqueUsers and not in staff: uniqueUsers.append(x)
elif x in staff and not in uniqueStaff: uniqueStaff.append(x)

When I try to import the module with the function definition that
contains this code, I get a syntax error pointing to the 'in' after the
'and not in staff'. I can't figure out why this is bad syntax. Both
'uniqueUsers' and 'staff' are lists.

thanks for your help!
 
J

James Thiele

Try:
for x in occupants:
if x not in uniqueUsers and x not in staff:
uniqueUsers.append(x)
elif x in staff and x not in uniqueStaff:
uniqueStaff.append(x)
 
G

Gerard Flanagan

orangeDinosaur said:
Here's a section of code:

for x in occupants:
if x not in uniqueUsers and not in staff: uniqueUsers.append(x)
elif x in staff and not in uniqueStaff: uniqueStaff.append(x)

When I try to import the module with the function definition that
contains this code, I get a syntax error pointing to the 'in' after the
'and not in staff'. I can't figure out why this is bad syntax. Both
'uniqueUsers' and 'staff' are lists.

thanks for your help!

I think you're missing an 'x':

for x in occupants:
if x not in Users and x not in Staff:
Users.append(x)

Gerard
 
A

Alex Martelli

orangeDinosaur said:
Here's a section of code:

for x in occupants:
if x not in uniqueUsers and not in staff: uniqueUsers.append(x)
elif x in staff and not in uniqueStaff: uniqueStaff.append(x)

When I try to import the module with the function definition that
contains this code, I get a syntax error pointing to the 'in' after the
'and not in staff'. I can't figure out why this is bad syntax. Both
'uniqueUsers' and 'staff' are lists.

say ...'and x not in staff' -- you need the x between 'and' and 'not',
and similarly for the elif (and don't use tabs -- they make a mess of a
display on many newsreaders etc -- fixed to spaces above).


Alex
 
J

Jorge Godoy

orangeDinosaur said:
Here's a section of code:

for x in occupants:
if x not in uniqueUsers and not in staff: uniqueUsers.append(x)
elif x in staff and not in uniqueStaff: uniqueStaff.append(x)

When I try to import the module with the function definition that
contains this code, I get a syntax error pointing to the 'in' after the
'and not in staff'. I can't figure out why this is bad syntax. Both
'uniqueUsers' and 'staff' are lists.

The question is: "what's not in XXX"? x? Something else? You hve to
remember that the computer does only what you tell it to do:

if x not in uniqueUsers and x not in staff: ...

I also prefer using parenthesis to make things more clear and avoid precedence
surprises.

--
Jorge Godoy <[email protected]>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top