Add 2 new articles

This commit is contained in:
Angelos Chalaris
2022-12-04 16:25:27 +02:00
parent e110a9aa50
commit 676110ee43
2 changed files with 58 additions and 0 deletions

21
blog_posts/css-clamp.md Normal file
View File

@ -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).

View File

@ -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}
# ]
```