0

Is there a simple way to declare variables in Python similar to R's ifelse?

In R for example:

outgroup <- ifelse(politics == "Republican", 1, 0)

In Python, I'm doing:

outgroup = 0
if politics == "Republican":
    outgroup = 1

Is there a simpler way of doing this in Python?

Parseltongue
  • 11,157
  • 30
  • 95
  • 160

0 Answers0