0

What is the equivalent in python of the expression below?

EE_DOUBLE const yplus = ( y < 1.0 ) ? y*u_tau/nu_inf : (2.0-y)*u_tau/nu_inf

Any suggestions are welcome. Many thanks A

too honest for this site
  • 11,417
  • 3
  • 27
  • 49
Andrei
  • 21
  • 6

3 Answers3

0

I'm not too sure about C syntax anymore, but i guess it'll look like this :

yplus =  y*u_tau/nu_inf if ( y < 1.0 ) else (2.0-y)*u_tau/nu_inf
Tbaki
  • 863
  • 6
  • 12
0
yplus = ((2.0-y)*u_tau/nu_inf, y*u_tau/nu_inf)[y < 1.0]

other way

yplus = (y < 1.0) and (y*u_tau/nu_inf) or ((2.0-y)*u_tau/nu_inf)

other way

yplus = {True: y*u_tau/nu_inf, False: (2.0-y)*u_tau/nu_inf} [y < 1.0]

other way marked already by others

yplus = (y*u_tau)/nu_inf if y < 1.0 else (2.0-y)*u_tau/nu_inf

other way

if (y < 1.0):
  yplus = (y*u_tau)/nu_inf
else:
  yplus = (2.0-y)*u_tau/nu_inf
alinsoar
  • 13,197
  • 4
  • 45
  • 63
  • I guess the expressions should be swapped. But nice idea. Is it idiomatic? – Eugene Sh. Jun 22 '17 at 15:17
  • @EugeneSh. the idea comes from lisp systems, where each operator can treat a value in different ways, for example here what is supposed to be a boolean is treated by []-ref operator as integer. – alinsoar Jul 03 '17 at 06:01
0

Using Python's ternary operator added since 2.5

yplus = (y*u_tau)/nu_inf if y < 1.0 else (2.0-y)*u_tau/nu_inf