Don't Use`For` in Python Anymore | by Miner Of Ideas

PHOTO EMBED

Tue Feb 27 2024 13:56:58 GMT+0000 (Coordinated Universal Time)

Saved by @viperthapa #python

list_of_dicts = [
    {'name': 'Alice', 'age': 30},
    {'name': 'Bob', 'age': 25},
    {'name': 'Charlie', 'age': 35}
]
person = next((item for item in list_of_dicts if item.get('name') == 'Bob'),  "person not found." )
print(f"Found: {person}")
content_copyCOPY

Alternative of forloop

https://freedium.cfd/https://python.plainenglish.io/dont-use-anymore-for-in-python-225586f1b0c4