Skip to content

Questions on lists #5

Description

@enryH

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions