0

I know there are many resource such as One line if-condition-assignment

but in my case I am assigning two variables from list with two items and want to know if there is a way of adding if statement in a line

my code is :

status, bytes = test_str[pos[1]+1:pos[2]-2].split()
if bytes == "-":
    bytes = 0

I want something like:

status, bytes if (bytes != "-" else 0) = test_str[pos[1]+1:pos[2]-2].split()
haneulkim
  • 3,674
  • 6
  • 21
  • 54

1 Answers1

1

I agree with @KlausD.'s comment, but if you really have to, use:

status, bytes = [test_str[pos[1]+1:pos[2]-2].split(), (test_str[pos[1]+1:pos[2]-2].split()[0],0)][test_str[pos[1]+1:pos[2]-2].split()[1] == "-"]
U12-Forward
  • 65,118
  • 12
  • 70
  • 89