← 输入框|python.land|刷新

Python List: How To Create, Sort, Append, Remove, And More

The Python list is one of the most used Python data structures, together with dictionaries. A list holds any number of values in a fixed order, and you can change it after you create it: add items, remove them, sort them, and so on.

If you came here to find out how to add something to a list, here’s the short answer. Use append() to add one item to the end of a list:

>>> fruits = ["apple", "banana"]
>>> fruits.append("cherry")
>>> fruits
['apple', 'banana', 'cherry']Code language: Python (python)

To add a whole list to another list, use extend() instead. I explain the difference, and the other ways to add items, in how to add to a list in Python below. After that, this article covers everything else you might want to know about Python lists:

  • how to create lists,
  • how to get, replace and remove items,
  • how to sort lists,
  • how to loop over the elements of a list with a for-loop or a list comprehension,
  • how to slice, reverse and copy a list,
  • … and more!

Every example in this article is working code that you can paste into the Python REPL to try for yourself.

How to create a Python list

Let’s start by creating a list. You write the values between square brackets, separated by commas. Empty brackets give you an empty list:

>>> my_list = [1, 2, 3]
>>> empty_list = []
>>> type(my_list)
<class 'list'>
>>> len(empty_list)
0Code language: Python (python)

The elements in a list can have any data type, and you can mix types in one list. You can even create a list of lists. The following lists are all valid:

my_list = [1, "Erik", {'age': 39}]
# This is a list with three lists inside
game_board = [[], [], []]Code language: Python (python)

Using the list() function

Python lists, like all Python data types, are objects. The list class is called list, with a lowercase L. If you want to convert another Python object to a list, you can use the list() function, which is actually the constructor of the list class itself. It takes one argument: an iterable object.

So you can convert anything iterable into a list. For example, you can turn a range into a list of actual values, or convert a Python set, a tuple or a string into a list:

>>> list(range(1, 4))
[1, 2, 3]
>>> list({1, 2, 2, 2, 3})
[1, 2, 3]
>>> list((1, 2, 3))
[1, 2, 3]
>>> list('abc')
['a', 'b', 'c']Code language: Python (python)

Ready to make your own list? Try the Python list exercise on our free learning platform. Create a list of destinations and print it to check the values and their order.

How to add to a list in Python

There are several ways to add elements to a list in Python. Which one you need depends on two questions: do you add one item or many, and should the original list change or do you want a new list? Here’s an overview:

What you wantUseChanges the list?
Add one item to the endmy_list.append(x)Yes
Add one item at a specific positionmy_list.insert(i, x)Yes
Add all items of another list (or any iterable)my_list.extend(other) or my_list += otherYes
Combine two lists into a new listlist1 + list2No, it creates a new list

Let’s go through them one by one.

Append to a Python list

List objects have several useful built-in methods, and append() is the one you’ll use most. It adds one object to the end of the list:

>>> my_list = [1, 2]
>>> my_list.append('a')
>>> my_list
[1, 2, 'a']
>>> my_list.append(4)
>>> my_list
[1, 2, 'a', 4]Code language: Python (python)

A very common pattern is to start with an empty list and append to it inside a loop:

>>> squares = []
>>> for n in range(1, 6):
...     squares.append(n * n)
...
>>> squares
[1, 4, 9, 16, 25]Code language: Python (python)

One mistake I see a lot: append() changes the list in place and returns None. So don’t assign its result back to your variable, or you lose your list:

>>> my_list = [1, 2, 3]
>>> my_list = my_list.append(4)
>>> print(my_list)
NoneCode language: Python (python)

Just write my_list.append(4) on its own line. The same goes for insert(), extend(), sort() and the other methods that change a list.

Want to practise? The lesson on adding items to a list has an exercise where you append items and check the order they end up in.

Insert an item at a specific position

append() always adds to the end. To add an item somewhere else, use insert(index, item). The new item ends up at that index, and everything after it moves one place to the right. Use index 0 to add an item to the front of the list:

>>> letters = ['a', 'c', 'd']
>>> letters.insert(1, 'b')
>>> letters
['a', 'b', 'c', 'd']
>>> letters.insert(0, 'start')
>>> letters
['start', 'a', 'b', 'c', 'd']
>>> letters.insert(100, 'end')
>>> letters
['start', 'a', 'b', 'c', 'd', 'end']Code language: Python (python)

As the last call shows, an index past the end of the list doesn’t raise an error. Python simply adds the item at the end.

Add a list to a list: append vs. extend

Here’s the mistake almost everyone makes once. You have two lists and want to add the items of the second list to the first, so you call append():

>>> l1 = [1, 2]
>>> l2 = [3, 4]
>>> l1.append(l2)
>>> l1
[1, 2, [3, 4]]
>>> len(l1)
3Code language: Python (python)

That’s probably not what you wanted. append() adds exactly one item, and here that item is the whole list [3, 4]. You end up with a nested list of three elements, not four.

To add each element of one list to another, use extend():

>>> l1 = [1, 2]
>>> l2 = [3, 4]
>>> l1.extend(l2)
>>> l1
[1, 2, 3, 4]
>>> l2
[3, 4]Code language: Python (python)

While l1 got extended with the elements of l2, l2 itself stayed the same.

So the rule is: append() adds one item, whatever it is. extend() takes an iterable and adds every item in it. That second part has its own surprise. A string is iterable too, so extending with a string adds each character separately:

>>> names = ['Erik']
>>> names.extend('Ana')
>>> names
['Erik', 'A', 'n', 'a']Code language: Python (python)

If you want to add one string, use names.append('Ana'), or wrap it in a list: names.extend(['Ana']).

Combine or merge two lists

If you’d rather keep both original lists intact, ‘add’ them together with the + operator. The result is a new, third list:

>>> l1 = [1, 2]
>>> l2 = [3, 4]
>>> l3 = l1 + l2
>>> l3
[1, 2, 3, 4]
>>> l1
[1, 2]Code language: Python (python)

The += operator looks similar, but it works like extend(): it changes the list on the left in place instead of creating a new one:

>>> l1 = [1, 2]
>>> l1 += [3, 4]
>>> l1
[1, 2, 3, 4]Code language: Python (python)

Both sides of + must be lists. You can’t add a single number to a list this way:

>>> my_list = [1, 2, 3]
>>> my_list + 4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    my_list + 4
    ~~~~~~~~^~~
TypeError: can only concatenate list (not "int") to listCode language: Python (python)

Write my_list + [4] or use append() instead.

Finally, you can build a new list from several lists with the * unpacking operator. This is handy when you want to mix whole lists and single values:

>>> l1 = [1, 2]
>>> l2 = [3, 4]
>>> [0, *l1, *l2, 5]
[0, 1, 2, 3, 4, 5]Code language: Python (python)

Add an item only if it’s not in the list yet

Lists happily store the same value more than once. If you want to avoid duplicates, check with not in before you append:

>>> tags = ['python', 'list']
>>> for tag in ['list', 'append']:
...     if tag not in tags:
...         tags.append(tag)
...
>>> tags
['python', 'list', 'append']Code language: Python (python)

If you never want duplicates and the order doesn’t matter, a Python set is often a better fit than a list.

Accessing Python list elements

To access an individual list element, you need to know its position, also called its index. Python starts counting at 0, so the first element is at index 0, the second element at index 1, and so on:

>>> my_list = [1, 2, 3]
>>> my_list[1]
2
>>> my_list[0]
1Code language: Python (python)

You can’t access elements that don’t exist. If you try, Python raises an IndexError:

>>> my_list = [1, 2, 3]
>>> my_list[4]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    my_list[4]
    ~~~~~~~^^^
IndexError: list index out of rangeCode language: Python (python)

An IndexError is an exception. In my article on exceptions and the try and except statements, I explain how to handle them, including a section on best practices.

Get the last element of a list

If you want to get elements from the end of the list, you can use a negative index. In this case, you start counting at -1 instead of 0. So to get the last element of a list, you do this:

>>> my_list = [1, 2, 3]
>>> my_list[-1]  # get the last element
3
>>> my_list[-2]  # get the 2nd last element
2Code language: Python (python)

Accessing nested list elements

Accessing nested list elements isn’t much different. When you access an element that is a list, you get that list back. To get an element from that inner list, you add a second pair of brackets:

>>> my_list = [[1, 2], [3, 4], [5, 6]]
>>> my_list[0]
[1, 2]
>>> my_list[0][0]
1
>>> my_list[2][1]
6Code language: Python (python)

Replace items in a list

To replace a list item, assign a new value to its index, like so:

>>> my_list = [1, 2, 3, 4, 5]
>>> my_list[0] = 400
>>> my_list
[400, 2, 3, 4, 5]Code language: Python (python)

Replacing an item keeps the list the same length. To make it longer, use one of the methods from the section on adding to a list.

How to remove items from a list

There are several ways to remove data from a list. What you use depends on whether you know the position of the item or its value, and on whether you still need the item afterward. I’ll demonstrate them all in this section.

Pop items from a list

The pop() method removes and returns the last item, unless you give it an index argument. Here are a couple of examples that show both the default behavior and the behavior when given an index:

>>> my_list = [1, 2, 3, 4, 5]
>>> my_list.pop()
5
>>> my_list.pop()
4
>>> my_list.pop(0)
1
>>> my_list
[2, 3]Code language: Python (python)

If you’re familiar with the concept of a stack (last in, first out), you can now build one using only the append() and pop() methods on a list!

Using del to delete items

While pop() returns the item it removes from the list, the del statement removes it without returning anything:

>>> my_list = [1, 2, 3, 4, 5]
>>> del my_list[0]
>>> my_list
[2, 3, 4, 5]
>>> del my_list[2]
>>> my_list
[2, 3, 5]Code language: Python (python)

del also works with a slice (more on slicing later), so you can remove several items at once:

>>> my_list = [1, 2, 3, 4, 5, 6]
>>> del my_list[1:3]
>>> my_list
[1, 4, 5, 6]Code language: Python (python)

del isn’t list-specific. It removes a name, so you can use it to delete the entire list variable too:

>>> my_list = [1, 2, 3]
>>> del my_list
>>> my_list
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    my_list
NameError: name 'my_list' is not definedCode language: Python (python)

Once nothing refers to an object anymore, Python can free up the memory it used. For small programs, you don’t have to bother. If you load a lot of data into memory, though, it can help to delete the data you don’t need anymore.

Remove specific values from a Python list

If you want to remove a specific value from the list, use the remove() method. It removes the first occurrence of the given value. Let’s demonstrate this by removing the number two from my_list:

>>> my_list = [1, 2, 3, 2, 5]
>>> my_list.remove(2)
>>> my_list
[1, 3, 2, 5]
>>> my_list.remove(2)
>>> my_list
[1, 3, 5]
>>> my_list.remove(2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    my_list.remove(2)
    ~~~~~~~~~~~~~~^^^
ValueError: list.remove(x): x not in listCode language: Python (python)

As you can see, repeated calls to remove() remove the next two until none are left, at which point Python raises a ValueError exception. If you’re not sure the value is there, check with if 2 in my_list: first.

Remove or clear all items from a Python list

To remove all items from a list, use the clear() method:

>>> my_list = [1, 2, 3]
>>> my_list.clear()
>>> my_list
[]Code language: Python (python)

Remove duplicates from a list

There’s no list method to remove duplicates, but there are two short tricks. The first uses a Python set. Sets are collections of objects, like lists, but they can only contain one of each element. By converting the list to a set and back to a list again, you remove all duplicates. The catch is that sets have no order, so you may lose the original order of your list.

If the order matters, use dict.fromkeys() instead. Dictionary keys are unique too, and dictionaries remember the order in which keys were added:

>>> my_list = [3, 1, 3, 2, 1]
>>> list(set(my_list))
[1, 2, 3]
>>> list(dict.fromkeys(my_list))
[3, 1, 2]Code language: Python (python)

If a set offers what you need, you may not have to convert it back into a list at all. Just keep using the set.

Remove items that match a condition

To remove all items that match some condition, the cleanest way is to build a new list with only the items you want to keep. A list comprehension does that in one line. Here, we keep only the even numbers:

>>> numbers = [1, 2, 3, 4, 5, 6]
>>> evens = [n for n in numbers if n % 2 == 0]
>>> evens
[2, 4, 6]Code language: Python (python)

Avoid calling remove() on a list while you loop over that same list. The positions shift under your loop, and it will skip items.

How to get list length in Python

In Python, you use the len() function to get the length of objects. This is true for lists as well:

>>> my_list = [1, 2, 3, 4, 5]
>>> len(my_list)
5Code language: Python (python)

If you’re familiar with other programming languages, like Java, you might wonder why Python has a function for this. After all, it could have been a method of the list, like my_list.len(). The reason is consistency. In other languages, each type tends to pick its own name: some call it len, others length or size, and some offer a public member variable instead. Python standardizes such a common operation: len() works on lists, strings, tuples, dictionaries, sets, and your own classes if you want it to.

Counting element occurrence in a list

Don’t confuse the count() method with getting the list length. They’re totally different. count() counts how often a particular value occurs in the list. Here’s an example:

>>> my_list = [1, 2, 1, 4, 1, 7]
>>> my_list.count(1)
3
>>> my_list.count(4)
1Code language: Python (python)

Since the number 1 occurs three times in the list, my_list.count(1) returns 3.

Check if an item is in a list

To check if an item is in a list, use the in operator. It returns True or False, and not in does the opposite:

>>> my_list = [1, 2]
>>> 1 in my_list
True
>>> 3 in my_list
False
>>> 3 not in my_list
TrueCode language: Python (python)

You’ll usually use it in an if statement, like if 1 in my_list:.

Find the index of an item in a list

You can find where an item is inside a list with the index() method. For example, in the following list, the 4 is at position 3 (remember that we start counting at zero):

>>> my_list = [1, 2, 3, 4, 5]
>>> my_list.index(4)
3Code language: Python (python)

The index() method takes two optional parameters: start and stop. With these, you can continue looking for more of the same value. You don’t need to supply a stop value if you provide a start value. Let’s find both 4s in the list below:

>>> my_list = [1, 2, 3, 4, 5, 4]
>>> my_list.index(4)
3
>>> my_list.index(4, 4)  # continue searching from position 4
5Code language: Python (python)

If the value isn’t in the list, index() raises a ValueError:

>>> my_list = [1, 2, 3]
>>> my_list.index(7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    my_list.index(7)
    ~~~~~~~~~~~~~^^^
ValueError: list.index(x): x not in listCode language: Python (python)

If you want to do more advanced filtering of lists, you should read my article on list comprehensions.

Loop over list elements

A list is iterable, so you can use a for-loop over the elements of a list, just like with any other iterable, using the for <element> in <iterable> syntax:

my_list = [1, 2, 3]
for n in my_list:
    print(n)Code language: Python (python)

Output:

1 2 3

If you need the index of each element as well, use the built-in enumerate() function. It gives you the index and the element together:

fruits = ['apple', 'banana', 'cherry']
for i, fruit in enumerate(fruits):
    print(i, fruit)Code language: Python (python)

Output:

0 apple 1 banana 2 cherry

Python list to string

To turn a list of strings into one string, use the join() method of the string you want between the elements. For a list of numbers, convert each number to a string first:

>>> fruits = ['apple', 'banana', 'cherry']
>>> ', '.join(fruits)
'apple, banana, cherry'
>>> numbers = [1, 2, 3]
>>> ', '.join(str(n) for n in numbers)
'1, 2, 3'Code language: Python (python)

If you want the list exactly as Python prints it, brackets and all, use the str() function. You can convert most objects to a string with it:

>>> str([1, 'abc', 2.3])
"[1, 'abc', 2.3]"Code language: Python (python)

If you’re interested, str is actually the Python string class, and calling str() constructs a new str object. The constructor looks for a special method (also called a dunder method) called __str__ on the object you give it. If it’s there, it calls it. There’s nothing more to it.

If you create your own classes and objects, you can implement the __str__ method yourself to offer a printable version of your objects.

Sorting Python lists

To sort a Python list, you have two options:

  1. Use the built-in sort() method of the list itself.
  2. Use Python’s built-in sorted() function.

Option one sorts in place. In other words, it doesn’t return anything. Instead, it modifies the list itself.

Option two returns a new list and leaves the original intact. Which one you use depends on whether you still need the list in its original order.

In-place list sort in ascending order

Let’s start with the simplest use case, sorting in ascending order:

>>> my_list = [10, 2, 5, 4, 2]
>>> my_list.sort()
>>> my_list
[2, 2, 4, 5, 10]Code language: Python (python)

Like append(), sort() returns None. So my_list = my_list.sort() throws your list away. Just call my_list.sort() on its own line.

In-place list sort in descending order

You can call the sort method with a reverse parameter. If it’s set to True, sort reverses the order:

>>> my_list = [10, 2, 5, 4, 2]
>>> my_list.sort(reverse=True)
>>> my_list
[10, 5, 4, 2, 2]Code language: Python (python)

Using sorted()

The following example shows how to sort a list in ascending order with sorted(), which returns a new list with the result:

>>> my_list = [10, 2, 5, 4, 2]
>>> sorted(my_list)
[2, 2, 4, 5, 10]
>>> my_list
[10, 2, 5, 4, 2]Code language: Python (python)

As you can see from the last statement, the original list is unchanged. Let’s do that again, but now in descending order:

>>> my_list = [10, 2, 5, 4, 2]
>>> sorted(my_list, reverse=True)
[10, 5, 4, 2, 2]
>>> my_list
[10, 2, 5, 4, 2]Code language: Python (python)

Sort with a key function

Both sort() and sorted() accept a key argument: a function that Python calls on each element to decide the order. For example, strings sort by character code by default, which puts every uppercase letter before every lowercase one. With key=str.lower, you get a case-insensitive sort. With key=len, you sort by length:

>>> names = ['bob', 'Alice', 'carol']
>>> sorted(names)
['Alice', 'bob', 'carol']
>>> sorted(names, key=str.lower)
['Alice', 'bob', 'carol']
>>> sorted(names, key=len)
['bob', 'Alice', 'carol']Code language: Python (python)

Unsortable lists

You can’t sort every list, since Python can’t compare all types with each other. You can sort a list of numbers, like integers and floats, because they have a defined order. You can sort a list of strings as well, since Python can compare strings too.

However, lists can contain any type of object, and Python can’t compare completely different objects, like numbers and strings, to each other. In such cases, Python raises a TypeError:

>>> my_mixed_list = [1, 'a', 2, 'B']
>>> my_mixed_list.sort()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    my_mixed_list.sort()
    ~~~~~~~~~~~~~~~~~~^^
TypeError: '<' not supported between instances of 'str' and 'int'Code language: Python (python)

Although the error might look cryptic, it’s logical once you know what’s going on. To sort a list, Python needs to compare the objects to each other. So at some point, its sorting algorithm checks if 'a' < 1, hence the error: '<' not supported between instances of 'str' and 'int'.

Slicing

Sometimes you need to get part of a list. Python has a powerful syntax for this, called slicing, and it makes working with lists much easier than in many other programming languages. Slicing works on Python lists and all other sequence types, like strings, tuples, and ranges.

The slicing syntax is as follows:

my_list[start:stop:step]

A couple of notes:

  • start is the first element position to include.
  • stop is exclusive, meaning that the element at position stop won’t be included.
  • step is the step size. More on this later.
  • start, stop, and step are all optional.
  • Negative values can be used too.
  • A slice is always a new list. The original list stays the same.

Slicing is easiest to understand from examples, so try these for yourself:

>>> my_list = [1, 2, 3, 4, 5, 6, 7, 8]
>>> my_list[0:3]  # get the first three elements of a list
[1, 2, 3]
>>> my_list[:3]  # start is 0 by default
[1, 2, 3]
>>> my_list[4:]  # skip the first 4 elements
[5, 6, 7, 8]
>>> my_list[2:5]  # elements at index 2, 3 and 4
[3, 4, 5]
>>> my_list[-3:]  # the last three elements
[6, 7, 8]Code language: Python (python)

The step value

The step value in a slice is one by default, which means every element in the range ends up in the slice. If you increase the step size, you step over elements. For example, a step size of two skips one element on each step. Let’s try this:

>>> my_list = [1, 2, 3, 4, 5, 6, 7, 8]
>>> my_list[::2]  # skip one each time
[1, 3, 5, 7]
>>> my_list[1::2]  # same, but start at index 1
[2, 4, 6, 8]Code language: Python (python)

Going backward

Like with list indexing, you can also use negative numbers in a slice. Here’s a little ASCII art to show you how counting backward in a list works:

my_list = [1 , 2, 3, 4, 5, 6] -6 -5 -4 -3 -2 -1 (these are the index numbers)

Just remember that you need a negative step size to go backward:

>>> my_list = [1, 2, 3, 4, 5, 6]
>>> my_list[-1:-3:-1]
[6, 5]
>>> my_list[::-1]
[6, 5, 4, 3, 2, 1]Code language: Python (python)

Reversing Python lists

There are three ways to reverse a list in Python:

  1. An in-place reverse, using the built-in reverse() method that every list has
  2. List slicing with a negative step size, which gives you a new list
  3. A reverse iterator, created with the reversed() function

They are explained in detail in the following sections.

Using the built-in reverse method

The list.reverse() method does an in-place reverse, meaning it reorders the list itself. It doesn’t return a new, reversed list. Here’s how to use reverse():

>>> lst = [1, 2, 3, 4]
>>> lst.reverse()
>>> lst
[4, 3, 2, 1]
>>> lst.reverse()
>>> lst
[1, 2, 3, 4]Code language: Python (python)

Reverse a list with list slicing

You can also reverse a list with slicing, using a step size of -1. The difference is that slicing gives you a new, second list and keeps the original list intact:

>>> lst = [1, 2, 3, 4]
>>> lst[::-1]
[4, 3, 2, 1]
>>> lst
[1, 2, 3, 4]Code language: Python (python)

Creating a reverse iterator

Finally, you can use the built-in reversed() function, which creates an iterator that returns the elements of the given list in reverse order. This is cheap in terms of CPU and memory. All the iterator does is walk backward over the list. It doesn’t move data around, and it doesn’t reserve extra memory for a second list. So if you need to loop over a (large) list in reverse, this should be your choice.

Here’s how you use it. Keep in mind that you can only use the iterator once, but it’s cheap to make a new one:

lst = [1, 2, 3, 4]
for i in reversed(lst):
    print(i)Code language: Python (python)

Output:

4 3 2 1

If you do want a reversed list from it, pass the iterator to list(): list(reversed(lst)) gives you [4, 3, 2, 1].

Copy a list

This one surprises many beginners. Assigning a list to a second variable doesn’t copy it. Both names now refer to the same list, so a change through one name shows up through the other:

>>> a = [1, 2, 3]
>>> b = a
>>> b.append(4)
>>> a
[1, 2, 3, 4]Code language: Python (python)

If you want two separate lists, make a copy with the copy() method:

>>> a = [1, 2, 3]
>>> b = a.copy()
>>> b.append(4)
>>> a
[1, 2, 3]
>>> b
[1, 2, 3, 4]Code language: Python (python)

A full slice, a[:], and list(a) make the same kind of copy. Note that this is a shallow copy: if your list contains other lists, the copy refers to the same inner lists.

Learn more about Python lists

Because there’s a lot to tell about list comprehensions, I created a dedicated article for the topic. A Python list comprehension is a language construct that you use to create a new list from an existing one in a single, readable line, without writing out a full for-loop.

Some other resources you might like:

  • The official Python docs about lists, including the full list of list methods.
  • If you’re interested in the internals: in CPython, the standard Python implementation, a list is a dynamic array of references to objects. That’s why getting an item by index and appending to the end are fast, while inserting or removing near the front of a long list is slower, because every element after it has to move.
  • Python also has arrays, which are very similar, and the term will be familiar to people coming from other programming languages. They are more efficient at storing data, but they can only store one type of data.

Related articles

6 thoughts on “Python List: How To Create, Sort, Append, Remove, And More”

  1. Example in: Using the list() function
    >>> list({1, 2, 2, 2, 3})
    [1, 2, 3]

    I don’t understand that. Curly brackets are a SET, aren’t they? Sets cannot contain duplicate values. That seems completely illogical to me, even if it works.

    • I can understand the confusion. When you create a set, you can add duplicates to it. But the set will filter out all duplicates. This is an often used trick in Python to de-duplicate a list: first create a set, so all duplicates are removed, and then convert it (back) to a list!

  2. I was a little floored by the len(my_list) line and my_list.len() not being a thing…
    my_list.__len__() is a thing though and I only tried that because of what I’ve learned so far in your tutorials/articles.
    Thanks!

  3. Hello,
    Just checking: when I call dir(list), one of the methods listed IS reverse. When I call that method on a list, it does in fact reverse it. I’m guessing this method got added after this article was written?

Leave a Comment