Skip to content
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

Questions on lists #5

Open
enryH opened this issue Apr 21, 2021 · 2 comments
Open

Questions on lists #5

enryH opened this issue Apr 21, 2021 · 2 comments

Comments

@enryH
Copy link
Collaborator

enryH commented Apr 21, 2021

Collection of questions on list

  • inplace manipulation using most list methods. How to copy a list?

Code-Snippets

## List copies

a = 40
another_list = [6, 4, 1, 2, 5, a]
list2 = list(another_list) #.copy()
another_list.sort()

print(another_list)
print(list2)




## Nested list copies

# create a list
inner_list = [40, 50, 60]


outer_list = [6, 4, 1, 2, 5, inner_list]
copy_outer_list = list(outer_list) #.copy()
# copy_outer_list = outer_list.copy()

print(outer_list)
print(copy_outer_list)


inner_list[2] = 500
outer_list[1] = 100
print(outer_list)
print(copy_outer_list)
@enryH
Copy link
Collaborator Author

enryH commented Apr 21, 2021

Maybe extend the modifying tricks section

numbers = [1, 2, 3, 4, 5]
numbers[1] = ['a','b','c'] 
print(numbers) 

numbers = [1, 2, 3, 4, 5]
numbers[1:2] = ['a','b','c'] 
print(numbers) 

numbers = [1, 2, 3, 4, 5]
numbers[1:3] = ['a','b','c'] 
print(numbers) 

numbers = [1, 2, 3, 4, 5]
numbers[1:4] = ['a','b','c'] 
print(numbers) 

@enryH
Copy link
Collaborator Author

enryH commented Apr 21, 2021

  • list comprehension in the lists.ipynb

In the current order, list comprehensions are introduced before loops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant