4259 links
  • Arnaud's links
  • Home
  • RSS Feed
  • Tag cloud
  • Login
search: tag:comprehension tag:list — newest first
  • Show some equivalent list comprehensions in filter examples · Issue #1068 · pallets/jinja · GitHub
    # filter out all elements not with x > 5
    a = [el for el in data if el['x'] > 5]
    
    # get all the 'c' attributes as a list
    b = [el['c'] for el in data]
    
    # get all the 'c' attributes for the elements with x > 5
    c = [el['c'] for el in data if el['x'] > 5]
    
    In Jinja2:
    
    a: {{ data | selectattr('x', 'gt', 5) | list }}
    b: {{ data | map(attribute='c') | list }} 
    c: {{ data | selectattr('x', 'gt', 5) | map(attribute='c') | list }} 
    
    September 24, 2021 - permalink - https://github.com/pallets/jinja/issues/1068
    ansible comprehension list python