Skip to content

Commit 586941e

Browse files
committed
update
1 parent 630232e commit 586941e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ permutations = itertools.permutations([1, 2, 3])
524524
- Jump Game
525525

526526

527-
## Understanding Infinity Comparisons
527+
## Understanding Comparisons
528528
### Distinct Value:
529529

530530
float('inf') represents a special value that is distinct from all finite numbers. In Python, this value is conceptually treated as an unbounded positive value. So, comparisons with float('inf') are straightforward and don't require tolerances because infinity is inherently larger than any finite number.
@@ -557,6 +557,17 @@ Syntax: a[start:stop:step] with start, stop, and step all set to their default v
557557
**In summary, there's no functional difference between the two in the context of copying a list; it's mainly a matter of style and readability. If you want to be explicit about the step value, you can use a[::].**
558558

559559

560+
### equality
561+
```python
562+
original_list = [1, 2, 3, 4, 5]
563+
copied_list = original_list[:]
564+
print(copied_list) # Output: [1, 2, 3, 4, 5]
565+
print(copied_list is original_list) # Output: False
566+
```
567+
- == operator: Checks for value equality (whether the contents of the objects are the same).
568+
569+
- is operator: Checks for identity equality (whether the variables point to the same object in memory).
570+
560571

561572

562573

exercise/pytricks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def count_characters(s):
7171

7272
return char_count
7373

74+
# Once a key is accessed in the default dict, key-default value will be initialized to it.
75+
m = defaultdict(int)
76+
print('a' in m) # output False
77+
m['a']
78+
print('a' in m) # output True
79+
7480
# Test the function
7581
input_string = "hello world"
7682
result = count_characters(input_string)

0 commit comments

Comments
 (0)