Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Python: List & dictionary comprehension

📅 2009-Oct-13 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ comprehensions, lists, python ⬩ 📚 Archive

#  Lists alist = [1, 2, 3] blist = [x*x for x in alist]    # [1, 4, 9]

# Dictionaries
adict = {3:"three", 5:"five", 1:"one"}
bdict = {num:None for num in adict} # {1: None, 3: None, 5: None}

© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 Mastodon📧 Email