-3

I have a python condition statement like this

if 'small_cover' not in request.POST or 'medium_cover' not in request.POST or 'large_cover' not in request.POST:
    # do somethinf here.

Can there be the shortest way than this.

MANOJ GOPI
  • 1,279
  • 10
  • 31
wrufesh
  • 1,379
  • 3
  • 18
  • 36

2 Answers2

1
if not all(x in request.POST for x in ('small_cover', 'medium_cover', 'large_cover')):

or even more concisely:

if not all(x+'_cover' in request.POST for x in ('small', 'medium', 'large')):
khelwood
  • 55,782
  • 14
  • 81
  • 108
1

Just use any which will short circuit if we find any of the three items are not in request.POST

if  any(x not in request.POST for x in ('small_cover',  'medium_cover','large_cover')):
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321