-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,261
  • 10
  • 29
wrufesh
  • 1,237
  • 1
  • 17
  • 32

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
  • 52,115
  • 13
  • 74
  • 94
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
  • 168,988
  • 22
  • 228
  • 312