From 676110ee4305845ad84e16e9bcb0f4c08c6721d7 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 4 Dec 2022 16:25:27 +0200 Subject: [PATCH] Add 2 new articles --- blog_posts/css-clamp.md | 21 +++++++++++ .../python-sort-dictionary-tuple-key.md | 37 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 blog_posts/css-clamp.md create mode 100644 blog_posts/python-sort-dictionary-tuple-key.md diff --git a/blog_posts/css-clamp.md b/blog_posts/css-clamp.md new file mode 100644 index 000000000..c4487ad1a --- /dev/null +++ b/blog_posts/css-clamp.md @@ -0,0 +1,21 @@ +--- +title: "Tip: Use clamp() in CSS for responsive typography" +shortTitle: CSS clamp() +type: tip +tags: css,visual +expertise: beginner +author: chalarangelo +cover: blog_images/strawberries.jpg +excerpt: Implement responsive typography with the CSS clamp() function. +firstSeen: 2022-12-28T05:00:00-04:00 +--- + +Responsive typography has been in fashion for a while now, but some developers find it hard to implement. This is usually due to confusing algebraic formulas or complex hacks. Luckily, CSS has introduced the `clamp()` function, which makes it easy to create responsive typography with a single line of code. All you need to do is set the minimum, maximum, and preferred value and the browser will do the rest. + +```css +h2 { + font-size: clamp(1.5rem, 5vw, 3rem); +} +``` + +For a more complex example, take a look at the [Fluid typography snippet](/css/s/fluid-typography). diff --git a/blog_posts/python-sort-dictionary-tuple-key.md b/blog_posts/python-sort-dictionary-tuple-key.md new file mode 100644 index 000000000..d5dddef1a --- /dev/null +++ b/blog_posts/python-sort-dictionary-tuple-key.md @@ -0,0 +1,37 @@ +--- +title: "Tip: Sort Python dictionary list using a tuple key" +shortTitle: Sort dictionary list using a tuple key +type: tip +tags: python,list,dictionary +expertise: intermediate +author: chalarangelo +cover: blog_images/matrix-flow.jpg +excerpt: Learn how to sort a Python dictionary list using a tuple key. +firstSeen: 2023-01-04T05:00:00-04:00 +--- + +Sorting a list of dictionaries in Python can seem intimidating at first. This is especially true if you want to sort using multiple keys. Luckily, the `sorted()` function can be used to sort a list of dictionaries using a tuple `key`. Simply return a tuple with the order of keys you want to sort by and the `sorted()` function will do the rest. + +```py +friends = [ + {"name": "John", "surname": "Doe", "age": 26}, + {"name": "Jane", "surname": "Doe", "age": 28}, + {"name": "Adam", "surname": "Smith", "age": 30}, + {"name": "Michael", "surname": "Jones", "age": 28} +] + +print( + sorted( + friends, + key=lambda friend: + (friend["age"], friend["surname"], friend["name"]) + ) +) +# PRINTS: +# [ +# {'name': 'John', 'surname': 'Doe', 'age': 26}, +# {'name': 'Jane', 'surname': 'Doe', 'age': 28}, +# {'name': 'Michael', 'surname': 'Jones', 'age': 28}, +# {'name': 'Adam', 'surname': 'Smith', 'age': 30} +# ] +```