From 7eb6a41602d81a1c2c2e0e8249a79ac8a831d8f6 Mon Sep 17 00:00:00 2001 From: eggy Date: Sat, 29 May 2021 22:10:51 -0400 Subject: [PATCH] Edit Python blog entry to fix typo and add another map example --- src/posts/2021/05/handy-python-tips.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/posts/2021/05/handy-python-tips.md b/src/posts/2021/05/handy-python-tips.md index 3bf639b..fdd532a 100644 --- a/src/posts/2021/05/handy-python-tips.md +++ b/src/posts/2021/05/handy-python-tips.md @@ -90,7 +90,7 @@ Output: ## 2. Nicer iteration with zip() and enumerate() -Python's for loop is commonly known in other programming languages as a for-each loop. This is great if you just want each item in an iterable, but sometimes you want the index too! Instead of having to resort to `range(len(array))`, instead you can use `enumerate()` and tuple expansionto easily get both the index of the element and the element itself: +Python's for loop is commonly known in other programming languages as a for-each loop. This is great if you just want each item in an iterable, but sometimes you want the index too! Instead of having to resort to `range(len(array))`, instead you can use `enumerate()` and tuple expansion to easily get both the index of the element and the element itself: ```python array = ["a", "b", "c", "d", "e"] @@ -222,6 +222,12 @@ Output: [1, 2, 3, 4, 5] ``` +It's most useful in assigning variables easily when you know the format the input will be in. + +```python +a, b = (map(int, input().split())) +``` + ## 5. List generators You can generate a new list using inline `for`.