Skip to content

arrays: exercise 2 #92

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions data_structures/2_Arrays/yash_solution/2_marvel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 2. You have a list of your favourite marvel super heros.
# ```
# heros=['spider man','thor','hulk','iron man','captain america']
# ```
# Using this find out,
# 1. Length of the list
# 2. Add 'black panther' at the end of this list
# 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'
# 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.
# 5. Sort the heros list in alphabetical order (Hint. Use dir() functions to list down all functions available in list)

# You have a list of your favourite marvel super heros.
heros=['spider man','thor','hulk','iron man','captain america']

# Using this find out
# 1. Length of the list
print(f'1. length of {heros} is {len(heros)}')

# 2. Add 'black panther' at the end of this list
heros.append('black panther')
print(f'2. Adding \'black panther\' at the end of the list: {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.remove('black panther')
heros.insert(3, 'black panther')
print(f'3. Adding \'black panther\' after hulk: {heros}')

# 4. remove thor & hulk, add 'captain strange' in their place
heros[1:3]=['doctor strange']
print(f'4. Replace thor & hulk with \'captain strange:\' {heros}')

# 5. Sort the heros list in alphabetical order (Hint. Use dir() functions to list down all functions available in list)
heros.sort()
print(f'5. sorted list: {heros}')