-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp2.py
More file actions
24 lines (23 loc) · 868 Bytes
/
Copy pathp2.py
File metadata and controls
24 lines (23 loc) · 868 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
# 2. You have a list of your favourite marvel super heros
# heros=['spider man','thor','hulk','iron man','captain america']
# Using this list
heros=['spider man','thor','hulk','iron man','captain america']
# 1. Length of the list
print(len(heros))
# 2. Add 'black panther' at the end of this list
heros.append('black panther')
print(heros)
# 3. You realize that you need to add 'black panther' after 'hulk',
# so remove it from the list first and then add it after 'hulk'
heros.pop()
print(heros)
heros.insert(3,"black panther")
print(heros)
# 4. Now you don't like thor and hulk because they get angry easily
# So you want to remove thor and hulk from list and replace them with doctor strange (because he is cool).
# Do that with one line of code.
heros[1:3]=['doctor strange']
print(heros)
# 5. Sort the list in alphabetical order
heros.sort()
print(heros)