I am trying to make a list
dynamic if a condition is met, not sure if it is entirely possible with python, especially with a list comprehension.
Here is my example code:
foobars = [
{
id: 1,
bar: 'foo'
}
]
all_foos = {
foobar['id']: foobar['bar']
for foobar in foobars if condition == 'x' else foobars.pop(len(foorbars - 2))
}
Trying to make the list foobars
dynamic by popping off the last two if a condition is met.
Essentially, I am trying to remove the last two list items if the django webpage renders in another country.
Open to suggestions and alternatives. Thanks.
Main issue is getting the conditional in the dict comprehension, not returning the last two items from the list.