Lists Flashcards

1
Q

Element

A

Each value in a list is referred to as an element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Lists Format

A

Lists are created using square brackets ‘[ ]’. The basic syntax to create a list is as follows: my_list = [element 1, element 2, element 3, …]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Empty List

A

You can create an empty list by using empty square brackets: empty_list = []

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Accessing Elements - Accessing a Single Element:

A
  • The elements in a list are numbered with integers starting from 0.
  • Access an individual list element by using the list’s name, followed by the element’s index enclosed in square brackets.

ex.) data = [2.71, 3.14, 1.41, 1.62]
print(data[1]) #Prints 3.14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Negative Indexes

A
  • Negative indexes will start from the end of the list.
  • The index ‘-1’ refers to the last element in the list.
  • The index ‘-2’ refers to the second last element in the list.

ex.) Courses = [‘History’, ‘Math’, ‘Physics’, ‘CompSci’]
print(courses[-2]) #prints Physics

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Modifying Lists

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Sorting Lists

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Looping Values

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Accessing Elements - Accessing Multiple Elements:

A

ex.) courses = [‘History’, ‘Math’, ‘Physics’, ‘CompSci’]
print(courses[0:2]) #prints History and Math

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Adding Elements to List Methods

A
  1. Append method
  2. Insert method
  3. Extend Method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Append Method

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Insert Method

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Extend Method

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly