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
  • 10,245
  • 27
  • 85
  • 148

0 Answers0