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
  • 4,406
  • 9
  • 38
  • 80

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] == "-"]
U13-Forward
  • 69,221
  • 14
  • 89
  • 114