Skip to content

Commit 057bfa8

Browse files
authored
Merge branch 'master' into namemain-finalqa
2 parents 1f2d2dd + 638222f commit 057bfa8

File tree

9 files changed

+74
-2
lines changed

9 files changed

+74
-2
lines changed

python-f-string/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Python's F-String: An Improved String Interpolation and Formatting Tool
1+
# Python's F-String for String Interpolation and Formatting
22

3-
This folder provides the code examples for the Real Python tutorial [Python's F-String: An Improved String Interpolation and Formatting Tool](https://realpython.com/python-f-string/).
3+
This folder provides the code examples for the Real Python tutorial [Python's F-String for String Interpolation and Formatting](https://realpython.com/python-f-strings/).

python-set-comprehension/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Python Set Comprehensions: How and When to Use Them
2+
3+
This folder provides the code examples for the Real Python tutorial [Python Set Comprehensions: How and When to Use Them](https://realpython.com/python-set-comprehension/).

python-set-comprehension/colors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
colors = {"blue", "red", "green", "orange", "green"}
2+
print(colors)
3+
colors.add("purple")
4+
print(colors)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
2+
3+
print({number**2 if number % 2 == 0 else number**3 for number in numbers})
4+
5+
result_set = set()
6+
for number in numbers:
7+
if number % 2 == 0:
8+
value = number**2
9+
else:
10+
value = number**3
11+
result_set.add(value)
12+
13+
print(result_set)

python-set-comprehension/emails.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
emails = {
2+
3+
4+
5+
6+
7+
8+
}
9+
10+
print({email.strip().lower() for email in emails})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
emails_set = {
2+
3+
4+
5+
6+
7+
}
8+
9+
print({email for email in emails_set if email.endswith(".com")})

python-set-comprehension/matrix.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
matrix = [
2+
[9, 3, 8, 3],
3+
[4, 5, 2, 8],
4+
[6, 4, 3, 1],
5+
[1, 0, 4, 5],
6+
]
7+
8+
print({value**2 for row in matrix for value in row})

python-set-comprehension/text.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
unique_words = set()
2+
text = """
3+
Beautiful is better than ugly
4+
Explicit is better than implicit
5+
Simple is better than complex
6+
Complex is better than complicated
7+
""".lower()
8+
9+
for word in text.split():
10+
unique_words.add(word)
11+
12+
print(unique_words)
13+
14+
print(set(text.split()))
15+
16+
unique_words = {word for word in text.split()}
17+
18+
print(unique_words)

python-set-comprehension/tools.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tools = ["Python", "Django", "Flask", "pandas", "NumPy"]
2+
tools_set = {tool.lower() for tool in tools}
3+
4+
print(tools_set)
5+
print("python".lower() in tools_set)
6+
print("Pandas".lower() in tools_set)
7+
print("Numpy".lower() in tools_set)

0 commit comments

Comments
 (0)