My code looks like this:
if query.orderby:
for q in query.orderby:
if 'severity' in q:
Note: query.orderby is a list of dict. Looks something like [{"severity": "asc"},{"name": "desc"}] How can i optimize these lines? Is there any way to replace the for loop and still get same functionality as the code above?
Something like this:
filtered = [q for q in query.orderby if 'severity' in q]
would filter into a new list
If query.orderby is a list of dict than you should go like that:
x = [{"severity": "asc"}, {"name": "desc"}]
for e in x:
for key, value in e.iteritems():
if 'severity' in key:
print 'yes'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With