-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists.py
More file actions
28 lines (22 loc) · 661 Bytes
/
Copy pathlists.py
File metadata and controls
28 lines (22 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# List Operations and Methods - Day 3 Example
# 1. Basic List Operations
fruits = ['apple', 'banana', 'cherry', 'date']
print('Original:', fruits)
# Adding elements
fruits.append('elderberry')
fruits.insert(2, 'blueberry')
print('After append & insert:', fruits)
# Removing elements
fruits.remove('banana')
popped = fruits.pop()
print('After remove & pop:', fruits, '| Popped:', popped)
# Slicing and indexing
print('First 3:', fruits[:3])
print('Last 2:', fruits[-2:])
print('Reversed:', fruits[::-1])
# List comprehensions
numbers = [x**2 for x in range(10) if x % 2 == 0]
print('Even squares:', numbers)
# Sorting
fruits.sort()
print('Sorted:', fruits)