Rearranging Lists

Description

We can manipulate the contents of lists by using the methods shuffle, sort and reverse. shuffle randomizes the order of the list items, while reverse reverses their order. sort automatically sorts from least to greatest, but will sort from greatest to least by using sort(reverse = true.

Sage Cell

Code

A = [ 2, 3, 5, 7, 11 ]
shuffle(A)
print A
A = [ 2, 3, 5, 7, 11 ]
A.reverse()
print A
A = [ 11, 5, 3, 7, 2 ]
A.sort()
print A
A = [ 11, 5, 3, 7, 2 ]
A.sort(reverse = true)
print A

Options

none

Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

Attribute

Permalink:

Author:

Date: 26 Mar 2019 16:00

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License