-
Notifications
You must be signed in to change notification settings - Fork 81
Update 06.Lists.md #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
txt0
wants to merge
1
commit into
pro1code1hack:main
Choose a base branch
from
txt0:patch-5
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,16 +400,16 @@ print(max(numbers)) # Output: 8 | |
|
||
# Nope, won't work, don't even try to do this! | ||
imposter_numbers = ['s', 15] | ||
print(min(imposter_numbers)) | ||
print(max(imposter_numbers)) | ||
``` | ||
|
||
#### Output | ||
|
||
``` | ||
8 | ||
Traceback (most recent call last): | ||
File "<string>", line 2, in <module> | ||
TypeError: '<' not supported between instances of 'list' and 'int' | ||
File "<string>", line 6, in <module> | ||
TypeError: '>' not supported between instances of 'int' and 'str' | ||
``` | ||
|
||
## 4. Methods of Lists | ||
|
@@ -437,7 +437,7 @@ These methods let you add elements to the list, either at the end, a specific po | |
| Method | Description | Example | Output | | ||
|-----------------|----------------------------------------------------|---------------------------------|-------------------------------| | ||
| `remove(x)` | Removes the first item from the list whose value is x. | `x.remove('a')` | `[1, 2, 3, 4]` | | ||
| `pop([i])` | Removes the item at the given position in the list, and returns it. | `x.pop(1)` | `[1, 3, 4]` | | ||
| `pop(i)` | Removes the item at the given position in the list, and returns it. | `x.pop(1)` | `[1, 3, 4]` | | ||
| `clear()` | Removes all items from the list. | `x.clear()` | `[]` | | ||
|
||
|
||
|
@@ -494,7 +494,7 @@ Kyiv | |
Washington | ||
``` | ||
|
||
Don't forget to call variables which make sense for data scructures like in the examples above. | ||
Don't forget to call variables which make sense for data structures like in the examples above. | ||
|
||
### 5.2 Using `for index in range(len(list))` | ||
|
||
|
@@ -652,7 +652,7 @@ Deep copying is more memory-intensive and can be slower for large lists. So use | |
|
||
List comprehensions provide a more readable and concise way to create lists by transforming each element of an iterable. | ||
|
||
They can be used in place of for loops for simplicity and efficiency, particularly when you're applying a single, straightforward transformation or condition to each element. Btw, they work faster than default loops. | ||
They can be used in place of `for` loops for simplicity and efficiency, particularly when you're applying a single, straightforward transformation or condition to each element. Btw, they work faster than default loops. | ||
|
||
### 7.1 Syntax | ||
|
||
|
@@ -664,7 +664,7 @@ They can be used in place of for loops for simplicity and efficiency, particular | |
[expression for item in iterable if condition] | ||
|
||
# If-else clause | ||
[if expression else expression for item in itreable] | ||
[expression_1 if condition else expression_2 for item in itreable] | ||
``` | ||
|
||
Basically it is the same as for loops and each `list comprehension` _can be rewriten_ into the `for` loop. | ||
|
@@ -727,11 +727,11 @@ for i in range(5): | |
["even", "odd", "even", "odd", "even"] | ||
``` | ||
|
||
But there is some known rules between programers where we <span style="color:green">should</span> or <span style="color:red"> shouldn't </span> use them. | ||
But there are some rules known by programers about when we <span style="color:green">should</span> or <span style="color:red"> shouldn't </span> use them. | ||
|
||
In some cases for simple operation it is a great tool which working much faster in terms of efficiency, but in other cases it can lead to unnecessary complexion which will result in bad maintainability and readability of the code. | ||
In some cases for simple operations it is a great tool working much faster in terms of efficiency, but in other cases it can lead to unnecessary complexion which will result in bad maintainability and readability of the code. | ||
|
||
Please, be careful using list comprehesnsions. | ||
Please, be careful using list comprehensions. | ||
|
||
|
||
### 7.2 For-Loop vs List Comprehension | ||
|
@@ -818,7 +818,7 @@ print(split_list) | |
|
||
These methods are especially powerful when used together, allowing for back-and-forth transformations between `strings` and `lists`. | ||
|
||
Sure, here's the corrected and reformatted list for your quiz: | ||
|
||
|
||
## 9. Quiz | ||
|
||
|
@@ -1143,4 +1143,4 @@ Enter the text: Please contact us at [email protected] or [email protected] fo | |
Extracted Emails: [email protected]; [email protected] | ||
``` | ||
|
||
Don't forget that while designing your program, remember to create an interactive and user-friendly interface! | ||
Don't forget that while designing your program, remember to create an interactive and user-friendly interface! |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This title should read ### 7. List comprehensions