Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

Commit 97d551a

Browse files
authored
Merge branch 'main' into add-data-visualization-in-UX
2 parents 85e36bb + 9b1798b commit 97d551a

9 files changed

Lines changed: 748 additions & 2 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
Title: 'Lists'
3+
Description: 'A List in C# is a dynamic data structure that stores multiple objects of a specified type.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Code Foundations'
7+
- 'Developer Tools'
8+
Tags:
9+
- 'Data Structures'
10+
- 'Lists'
11+
CatalogContent:
12+
- 'learn-c-sharp'
13+
- 'paths/computer-science'
14+
---
15+
16+
A **`List`** in [C#](https://www.codecademy.com/resources/docs/c-sharp) is a dynamic [data structure](https://www.codecademy.com/resources/docs/general/data-structures) that stores multiple objects of a specified type. These objects can be accessed by their zero-based index. Unlike [arrays](https://www.codecademy.com/resources/docs/c-sharp/arrays). Lists can grow to accommodate a very large number of elements (up to about 2 billion), limited primarily by available system memory and the maximum value of an integer index."
17+
18+
## Syntax
19+
20+
> **Note:** Before creating a list, include the `System.Collections.Generic` namespace.
21+
22+
There are two common ways to create a `List` in C#:
23+
24+
```pseudo
25+
// Creating a List without any elements
26+
List<T> myList = new List<T>();
27+
```
28+
29+
Or alternatively:
30+
31+
```pseudo
32+
// Creating a List with three elements
33+
List<T> myList = new List<T> { element1, element2, element3 };
34+
```
35+
36+
**Parameters:**
37+
38+
- `T`: Represents any data type.
39+
- `element`: Any object or variable of type `T`.
40+
41+
## Example: Creating and Accessing a List
42+
43+
In this example, a list is created, numbers are added, and elements are accessed by their index:
44+
45+
```cs
46+
using System;
47+
using System.Collections.Generic;
48+
49+
class Program
50+
{
51+
static void Main()
52+
{
53+
// Create a list of integers
54+
List<int> numbers = new List<int>();
55+
56+
// Add elements to the list
57+
numbers.Add(10);
58+
numbers.Add(20);
59+
numbers.Add(30);
60+
61+
// Access elements by index
62+
Console.WriteLine(numbers[0]);
63+
Console.WriteLine(numbers[1]);
64+
Console.WriteLine(numbers[2]);
65+
}
66+
}
67+
```
68+
69+
The output of this code is:
70+
71+
```shell
72+
10
73+
20
74+
30
75+
```
76+
77+
## Codebyte Example: Printing elements in a List
78+
79+
This example creates a new `List` that stores three numbers. Since each element has an index, we can print each element in the `numbers` list by its index:
80+
81+
```codebyte/csharp
82+
using System;
83+
using System.Collections.Generic;
84+
85+
public class Test
86+
{
87+
public static void Main()
88+
{
89+
List<int> numbers = new List<int> { 2, 5, 10 };
90+
91+
Console.WriteLine(numbers[0]);
92+
Console.WriteLine(numbers[1]);
93+
Console.WriteLine(numbers[2]);
94+
}
95+
}
96+
```

content/java/concepts/strings/terms/equals/equals.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class MyClass {
3636

3737
// With string objects
3838
String myFavoriteLanguage = "Java";
39-
String codeNinjasFavoriteLangauge = "Java";
40-
System.out.println(myFavoriteLanguage.equals(codeNinjasFavoriteLangauge));
39+
String codeNinjasFavoriteLanguage = "Java";
40+
System.out.println(myFavoriteLanguage.equals(codeNinjasFavoriteLanguage));
4141
}
4242
}
4343
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
Title: 'join()'
3+
Description: 'Combines columns from another DataFrame into the calling DataFrame based on the index or a key column.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'DataFrame'
9+
- 'Join'
10+
- 'Pandas'
11+
- 'Python'
12+
CatalogContent:
13+
- 'learn-python-3'
14+
- 'paths/computer-science'
15+
---
16+
17+
In Pandas, **`DataFrame.join()`** combines columns from another DataFrame (or multiple DataFrames) into the calling DataFrame based on the index or a key column. It’s mainly used for merging DataFrames with different sets of columns but shared row indices.
18+
19+
## Syntax
20+
21+
```pseudo
22+
DataFrame.join(other, on=None, how='left', lsuffix='', rsuffix='', sort=False, validate=None)
23+
```
24+
25+
**Parameters:**
26+
27+
- `other`: Objects to join with the caller DataFrame.
28+
- `on`: Column(s) in the caller DataFrame to join on; must match the index in `other` if provided.
29+
- `how`: Type of join to perform — 'left', 'right', 'outer', or 'inner'.
30+
- `lsuffix`: Suffix to add to overlapping column names from the left DataFrame.
31+
- `rsuffix`: Suffix to add to overlapping column names from the right DataFrame.
32+
- `sort`: Sort the result DataFrame by the join keys if True.
33+
- `validate`: Checks if the join is of a specific type ('one_to_one', 'one_to_many', 'many_to_one', 'many_to_many').
34+
35+
**Return value:**
36+
37+
Returns a new DataFrame with columns of both joined DataFrames combined according to the join logic.
38+
39+
## Example
40+
41+
In this example, a list of words is joined into a single string separated by spaces:
42+
43+
```py
44+
words = ['Codecademy', 'is', 'awesome']
45+
result = ' '.join(words)
46+
print(result)
47+
```
48+
49+
This code produces the following output:
50+
51+
```shell
52+
Codecademy is awesome
53+
```
54+
55+
## Codebyte Example
56+
57+
In this example, a list of characters is joined into a single string separated by commas:
58+
59+
```codebyte/python
60+
print(','.join(['a', 'b', 'c']))
61+
```
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
Title: 'singledispatch()'
3+
Description: 'Turn a function into a single-dispatch generic function, allowing different implementations to be registered based on the type of the first argument.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Data Science'
7+
Tags:
8+
- 'Function'
9+
- 'Decorators'
10+
CatalogContent:
11+
- 'learn-python-3'
12+
- 'paths/data-science'
13+
---
14+
15+
In Python, **`functools.singledispatch`** is a [decorator](https://www.codecademy.com/resources/docs/python/decorators) that converts a [function](https://www.codecademy.com/resources/docs/python/functions) into a generic function(a type single function that can perform different actions depending on the data type of the input it receives) with behavior varying by the type of its first argument. It simplifies type-specific logic by allowing separate implementations to be registered instead of relying on multiple [if statements](https://www.codecademy.com/resources/docs/python/conditionals).
16+
17+
## Syntax
18+
19+
The `singledispatch()` function is included in the `functools` [module](https://www.codecademy.com/resources/docs/python/functools-module):
20+
21+
```py
22+
@functools.singledispatch
23+
def func(arg, ...):
24+
...
25+
```
26+
27+
**Parameters:**
28+
29+
- Takes a single callable (function) as the argument when used as a decorator.
30+
- The decorated function must accept at least one argument (the one whose type determines dispatch).
31+
32+
**Return value:**
33+
34+
- `singledispatch()` returns a single-dispatch generic function object.
35+
- Additional implementations can be registered for different types using the .register(type) method on the generic function.
36+
37+
## Example 1: Creat a generic function `process`
38+
39+
This example uses the `singledispatch` decorator to handle different input types in a custom way:
40+
41+
```py
42+
from functools import singledispatch
43+
44+
@singledispatch
45+
def process(value):
46+
print("Processing:", value)
47+
48+
@process.register(int)
49+
def _(value):
50+
print("Processing an integer:", value)
51+
52+
@process.register(str)
53+
def _(value):
54+
print("Processing a string:", value)
55+
56+
# Function calls
57+
process(10)
58+
process("Hello")
59+
```
60+
61+
Here is the output for this code:
62+
63+
```shell
64+
Processing an integer: 10
65+
Processing a string: Hello
66+
```
67+
68+
## Codebyte Example: Basic type-based greeting
69+
70+
This minimal example shows how `singledispatch()` changes behavior based on the type of its first argument:
71+
72+
```codebyte/python
73+
from functools import singledispatch
74+
75+
@singledispatch
76+
def greet(value):
77+
print("Hello!")
78+
79+
@greet.register(str)
80+
def _(value):
81+
print(f"Hello, {value}!")
82+
83+
greet("Alice")
84+
greet(42)
85+
```
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
Title: 'update_wrapper()'
3+
Description: 'Updates a wrapper function to look like the wrapped function by copying attributes like `__name__`, `__doc__`, and `__module__`.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Data Science'
7+
- 'Web Development'
8+
Tags:
9+
- 'Best Practices'
10+
- 'Decorators'
11+
- 'Functions'
12+
- 'Metadata'
13+
CatalogContent:
14+
- 'learn-python-3'
15+
- 'paths/computer-science'
16+
---
17+
18+
The **`update_wrapper()`** function from the `functools` module updates a wrapper function to look like the wrapped function by copying attributes such as `__name__`, `__doc__`, and `__module__`. This is essential for creating decorators that preserve the original function's metadata, making debugging and introspection much easier.
19+
20+
## Syntax
21+
22+
```pseudo
23+
from functools import update_wrapper
24+
25+
update_wrapper(wrapper, wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES)
26+
```
27+
28+
**Parameters:**
29+
30+
- `wrapper`: The function that is acting as a wrapper (e.g., inside a decorator).
31+
- `wrapped`: The original function being wrapped.
32+
- `assigned`: A tuple of attribute names to copy (defaults to `WRAPPER_ASSIGNMENTS`).
33+
- `updated`: A tuple of attribute names to update (defaults to `WRAPPER_UPDATES`).
34+
35+
**Return value:**
36+
37+
The `update_wrapper()` function returns the `wrapper` function itself, after updating it with the attributes of `wrapped`.
38+
39+
## Example
40+
41+
This example demonstrates how `update_wrapper()` preserves the original function's metadata when creating a decorator:
42+
43+
```py
44+
from functools import update_wrapper
45+
46+
def my_decorator(func):
47+
def wrapper(*args, **kwargs):
48+
print(f"Calling {func.__name__}")
49+
return func(*args, **kwargs)
50+
51+
# Update the wrapper to look like the original function
52+
update_wrapper(wrapper, func)
53+
return wrapper
54+
55+
@my_decorator
56+
def greet(name):
57+
"""A simple greeting function."""
58+
return f"Hello, {name}!"
59+
60+
# Check that metadata is preserved
61+
print(f"Function name: {greet.__name__}")
62+
print(f"Function docstring: {greet.__doc__}")
63+
```
64+
65+
Here is the output:
66+
67+
```shell
68+
Function name: greet
69+
Function docstring: A simple greeting function.
70+
```
71+
72+
## Codebyte Example
73+
74+
This codebyte example shows the difference between using and not using `update_wrapper()`:
75+
76+
```codebyte/python
77+
from functools import update_wrapper
78+
79+
def decorator_without_update(func):
80+
def wrapper(*args, **kwargs):
81+
print(f"Executing {func.__name__}")
82+
return func(*args, **kwargs)
83+
return wrapper
84+
85+
def decorator_with_update(func):
86+
def wrapper(*args, **kwargs):
87+
print(f"Executing {func.__name__}")
88+
return func(*args, **kwargs)
89+
90+
# This preserves the original function's metadata
91+
update_wrapper(wrapper, func)
92+
return wrapper
93+
94+
@decorator_without_update
95+
def function1():
96+
"""This is function1."""
97+
return "Hello from function1"
98+
99+
@decorator_with_update
100+
def function2():
101+
"""This is function2."""
102+
return "Hello from function2"
103+
104+
# Check metadata preservation
105+
print("Without update_wrapper:")
106+
print(f"Name: {function1.__name__}")
107+
print(f"Docstring: {function1.__doc__}")
108+
109+
print("\nWith update_wrapper:")
110+
print(f"Name: {function2.__name__}")
111+
print(f"Docstring: {function2.__doc__}")
112+
113+
# Call the functions
114+
print(f"\nResult: {function1()}")
115+
print(f"Result: {function2()}")
116+
```

0 commit comments

Comments
 (0)