Skip to content

Commit

Permalink
Merge branch 'master' into python-for-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-martin authored Dec 19, 2024
2 parents f9e63d5 + 21c0a2e commit eda34e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
2 changes: 1 addition & 1 deletion how-to-remove-item-from-list-python/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# How to Remove Items From Lists in Python

This folder provides the code examples for the Real Python tutorial [How to Remove Items From Lists in Python](https://realpython.com/how-to-remove-item-from-list-python/).
This folder provides the code examples for the Real Python tutorial [How to Remove Items From Lists in Python](https://realpython.com/remove-item-from-list-python/).
6 changes: 3 additions & 3 deletions how-to-remove-item-from-list-python/books.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
books.remove("The Hobbit")
print(books)

books = ["Dragonsbane", "The Hobbit", "Wonder", "Jaws"]
books.remove("The Two Towers")
print(books)
# books = ["Dragonsbane", "The Hobbit", "Wonder", "Jaws"]
# books.remove("The Two Towers")
# print(books)

books = ["Dragonsbane", "The Hobbit", "Wonder", "Jaws"]
del books[0:3]
Expand Down
32 changes: 6 additions & 26 deletions how-to-remove-item-from-list-python/phone_book.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
phone_numbers = [
"54123",
"54123",
"54123",
"54456",
"54789",
"54789",
]
phone_numbers = ["54123", "54123", "54456", "54789", "54789", "54123"]
for phone_number in phone_numbers[:]:
if phone_numbers.count(phone_number) > 1:
while phone_numbers.count(phone_number) > 1:
phone_numbers.remove(phone_number)
print(phone_numbers)


phone_numbers = [
"54123",
"54123",
"54123",
"54456",
"54789",
"54789",
]
phone_numbers = ["54123", "54123", "54456", "54789", "54789", "54123"]
phone_numbers = list(dict.fromkeys(phone_numbers))
print(phone_numbers)

phone_numbers = [
"54123",
"54123",
"54123",
"54456",
"54789",
"54789",
]
set(phone_numbers)

phone_numbers = ["54123", "54123", "54456", "54789", "54789", "54123"]
phone_numbers = set(phone_numbers)
print(phone_numbers)

0 comments on commit eda34e8

Please sign in to comment.