
Liu Lin
Articles
-
Dec 11, 2024 |
zlliu.medium.com | Liu Lin
# eg. on UpArrowKey keypress, do somethingLiu Zuo Lin·Follow3 min read·--Read Free: https://zlliu.medium.com/i-wrote-a-pypi-package-to-allow-python-to-react-to-keypresses-a9e92eff0e65?sk=389a06aac5bd78a11bd8d17e19cb2b0dImagine: In terminal, Python waits for you to press some keys. And when you press certain keys, certain function calls happen.
-
Dec 7, 2024 |
zlliu.medium.com | Liu Lin
Liu Zuo Lin·Follow5 min read·--Read free: https://zlliu.medium.com/7-things-i-regret-not-knowing-earlier-about-python-generators-bb04ccecab20?sk=ec2e0b9bf1948a5cf3701e72c74f40bcA generator function is a function that returns a generator object. A generator object loads data lazily (only when we tell it explicitly to), usually when we iterate through it eg. using a for loop. Here’s a simple example of a generator function.
-
Dec 5, 2024 |
zlliu.medium.com | Liu Lin
Liu Zuo Lin·Follow3 min read·--Read Free: https://zlliu.medium.com/i-wrote-a-pypi-package-to-visualize-heapq-heaps-b97194c899ef?sk=139bbf1b60b1f08227b5433d2d45cb9eIf you’re a beginner trying to understand Python’s heapq heaps, this is the article/package for you. A package to visualize heapq heaps easily for beginners. A heap is a binary tree. We have mainly 2 kinds of heaps — maximum heaps and minimum heaps. In minimum heaps, every parent ≤ their children.
-
Dec 4, 2024 |
zlliu.medium.com | Liu Lin
Liu Zuo Lin · Follow 2 min read · -- Read Free: https://zlliu.medium.com/today-i-learnt-we-cannot-use-to-escape-in-python-f-strings-3cf03e35f546?sk=71f816db7cbfd77b42509efc13d169d9 name = "tom" age = 20 You want to create the string "name=tom {20}" Intuitively, we might try to do this: name = "tom" age = 20 s = f"{name=}: \{{age}\}" print(s) But we get an error SyntaxError: f-string: single ‘}’ is not allowed ^ we cannot use \ to escape a { or } in an f-string! Do we have to resign to our...
-
Nov 30, 2024 |
zlliu.medium.com | Liu Lin
Liu Zuo Lin·Follow6 min read·--Read Free: https://zlliu.medium.com/9-python-collections-things-i-regret-not-knowing-earlier-21ed463f37fa?sk=d337b7052275c153b40fb537c6fa33e7Let’s say we are given a list of strings, and we need to count the number of occurrences of each string in the list. Using a dictionary is one basic way we could do this:But did you know that we can also use collections.Counter to do this?
Try JournoFinder For Free
Search and contact over 1M+ journalist profiles, browse 100M+ articles, and unlock powerful PR tools.
Start Your 7-Day Free Trial →