Skip to content

Commit 4bbe2e2

Browse files
Merge branch 'main' into fix-javascript-arguments-description
2 parents fba530a + 6dfcf1f commit 4bbe2e2

File tree

5 files changed

+213
-1
lines changed

5 files changed

+213
-1
lines changed

bin/concept-of-the-week.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
content/kotlin/concepts/variables/variables.md
1+
content/kotlin/concepts/classes/classes.md
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
Title: 'cbegin()'
3+
Description: 'Returns a constant iterator pointing to either the first element of the unordered set or the first element in a specific bucket.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Iterators'
9+
- 'Sets'
10+
- 'STL'
11+
CatalogContent:
12+
- 'learn-c-plus-plus'
13+
- 'paths/computer-science'
14+
---
15+
16+
The **`cbegin()`** method returns a constant iterator that points to the first element of an [`unordered_set`](https://www.codecademy.com/resources/docs/cpp/unordered-set). A constant iterator allows read-only access to elements and prevents modification. Because `unordered_set` does not maintain any defined order, the element returned by `cbegin()` depends on its internal hash table structure.
17+
18+
## Syntax
19+
20+
```pseudo
21+
unordered_set_name.cbegin(n);
22+
```
23+
24+
**Return value:**
25+
26+
Returns a `const_iterator` (constant iterator) pointing to the first element in the `unordered_set`.
27+
28+
Or, alternatively:
29+
30+
```pseudo
31+
unordered_set_name.cbegin(n);
32+
```
33+
34+
**Parameters:**
35+
36+
- `n` (size_type): The bucket index. Must be less than `bucket_count()`.
37+
38+
**Return value:**
39+
40+
A `const_local_iterator` pointing to the first element in bucket `n`. If the bucket is empty, the returned iterator equals `cend(n)`.
41+
42+
## Example
43+
44+
This example demonstrates obtaining the starting element of an `unordered_set` using `cbegin()`:
45+
46+
```cpp
47+
#include <iostream>
48+
#include <string>
49+
#include <unordered_set>
50+
using namespace std;
51+
52+
int main() {
53+
unordered_set<int> unique_numbers = {10, 5, 20, 15};
54+
55+
auto it = unique_numbers.cbegin();
56+
57+
cout << "The first element in internal order is: " << *it << "\n";
58+
59+
++it;
60+
if (it != unique_numbers.cend()) {
61+
cout << "The second element is: " << *it << "\n";
62+
}
63+
64+
// *it = 99; // Error: cannot modify through const_iterator
65+
66+
return 0;
67+
}
68+
```
69+
70+
A sample output of this code is:
71+
72+
```shell
73+
The first element in the set's internal order is: 20
74+
The second element is: 5
75+
```
76+
77+
> **Note:** Attempting to modify the element pointed to by the `const_iterator` would result in a compilation error.
78+
79+
## Codebyte Example
80+
81+
In this example, the code retrieves a constant iterator for a specific bucket in the `unordered_set` and prints all elements stored in that bucket:
82+
83+
```codebyte/cpp
84+
#include <iostream>
85+
#include <unordered_set>
86+
using namespace std;
87+
88+
int main() {
89+
unordered_set<string> words = {"cat", "dog", "rabbit", "lion"};
90+
91+
size_t bucket = 0;
92+
93+
auto it = words.cbegin(bucket);
94+
auto end = words.cend(bucket);
95+
96+
cout << "Elements in bucket " << bucket << ":\n";
97+
98+
for (; it != end; ++it) {
99+
cout << " " << *it << "\n";
100+
}
101+
102+
return 0;
103+
}
104+
```
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
Title: '.plot()'
3+
Description: 'Creates line and marker plots to visualize relationships between variables in Matplotlib.'
4+
Subjects:
5+
- 'Data Science'
6+
- 'Data Visualization'
7+
Tags:
8+
- 'Charts'
9+
- 'Matplotlib'
10+
- 'Methods'
11+
- 'Python'
12+
CatalogContent:
13+
- 'learn-python-3'
14+
- 'paths/data-science'
15+
- 'paths/data-science-foundations'
16+
---
17+
18+
The **`.plot()`** function in [Matplotlib](https://www.codecademy.com/resources/docs/matplotlib/pyplot) is the primary method used to create line plots and marker plots. It takes one or two sets of data points (x and y coordinates) and draws lines connecting them, displays markers at each point, or both. This function is one of the most commonly used tools in data visualization for showing trends, patterns, and relationships between variables.
19+
20+
Line plots are ideal for illustrating how data changes over time or across continuous intervals. It's widely used in fields such as statistics, engineering, and data science for exploratory data analysis and model visualization.
21+
22+
## Syntax
23+
24+
```pseudo
25+
matplotlib.pyplot.plot(*args, scalex=True, scaley=True, data=None, **kwargs)
26+
```
27+
28+
**Parameters:**
29+
30+
- `*args`: Values for y, or x and y, optionally followed by a format string.
31+
- `scalex`: Auto-scale the x-axis (default True).
32+
- `scaley`: Auto-scale the y-axis (default True).
33+
- `data`: Optional dict or DataFrame for referencing variables by name.
34+
- `**kwargs`: Style and configuration options like color, label, linewidth, marker.
35+
36+
**Return value:**
37+
38+
Returns a list of `Line2D` objects representing the plotted data.
39+
40+
## Example: Creating a Basic Line Plot
41+
42+
This example demonstrates how to create a simple line plot with plt.plot() to visualize the relationship between two numerical variables:
43+
44+
```py
45+
import matplotlib.pyplot as plt
46+
import numpy as np
47+
48+
# Sample data
49+
x = np.array([1, 2, 3, 4, 5])
50+
y = np.array([2, 4, 1, 6, 3])
51+
52+
# Create a line plot
53+
plt.plot(x, y)
54+
55+
# Add labels and a title
56+
plt.xlabel('X-axis')
57+
plt.ylabel('Y-axis')
58+
plt.title('Basic Line Plot Example')
59+
60+
# Add a grid for better readability
61+
plt.grid(True, linestyle='--', alpha=0.6)
62+
63+
# Display the plot
64+
plt.show()
65+
```
66+
67+
This example visualizes the relationship between an independent variable, X-axis, and a dependent variable, Y-axis, using a single continuous line. The plot shows the change in Y values as X increases from 1.0 to 5.0. This plot highlights a few useful details worth noting:
68+
69+
- Single Series: The plot displays one series of data, represented by a single blue line, showing the progression of the Y-axis value relative to the X-axis value.
70+
- Data Points and Trend: The line connects the following data points: $(1.0, 2.0)$, $(2.0, 4.0)$, $(3.0, 1.0)$, $(4.0, 6.0)$, and $(5.0, 3.0)$. The plot illustrates clear changes in direction: an initial increase, a sharp decrease, a significant increase to the maximum value, and a final decrease.
71+
- Labels and Title: The plot is clearly titled "Basic Line Plot Example" and has "X-axis" and "Y-axis" labels for clarity.
72+
- Grid: A light dashed grid is present, running horizontally and vertically across the plot, which aids in precisely reading the coordinate values of the data points off the chart.
73+
74+
![Line plot illustrating a fluctuating, piecewise linear trend between the X-axis and Y-axis, with a single blue line connecting 5 data points, a grid, and labeled axes](https://raw.githubusercontent.com/Codecademy/docs/main/media/matplot-plot-output.png)

content/sql/concepts/joins/joins.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,40 @@ An `OUTER JOIN` will combine rows from different tables even if the join conditi
4040
- [`RIGHT JOIN`](https://www.codecademy.com/resources/docs/sql/commands/right-join), which combines matches with all rows from the right-side table.
4141
- [`FULL OUTER JOIN`](https://www.codecademy.com/resources/docs/sql/commands/full-outer-join), which combines matches with all rows from the left- and right-side tables.
4242

43+
## CROSS JOIN
44+
45+
A `CROSS JOIN` clause combines each row from one table with each row from another in the result set. This result is also known as a `Cartesian product`. The following query returns every combination of `shirt_color` and `pants_color`:
46+
47+
```sql
48+
SELECT shirts.shirt_color,
49+
pants.pants_color
50+
FROM shirts
51+
CROSS JOIN pants;
52+
```
53+
54+
For example, here's the `shirts` table:
55+
56+
| shirt_color |
57+
| ----------- |
58+
| white |
59+
| grey |
60+
61+
And the `pants` table:
62+
63+
| pants_color |
64+
| ----------- |
65+
| light |
66+
| dark |
67+
68+
The result of the query would contain every combination of the two tables:
69+
70+
| shirt_color | pants_color |
71+
| ----------- | ----------- |
72+
| white | light |
73+
| white | dark |
74+
| grey | light |
75+
| grey | dark |
76+
4377
## UNION
4478

4579
The [`UNION`](https://www.codecademy.com/resources/docs/sql/commands/union) clause is used to combine results that appear from multiple [`SELECT`](https://www.codecademy.com/resources/docs/sql/commands/select) statements and filter duplicates.

media/matplot-plot-output.png

34.2 KB
Loading

0 commit comments

Comments
 (0)