This community-built FAQ covers the “Review” exercise from the lesson “Working with Lists in Python”.
Paths and Courses
This exercise can be found in the following Codecademy content:
Computer Science
FAQs on the exercise Review
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply ( ) below!
Agree with a comment or answer? Like ( ) to up-vote the contribution!
Need broader help or resources ? Head here .
Looking for motivation to keep learning? Join our wider discussions .
Learn more about how to use this guide.
Found a bug ? Report it!
Have a question about your account or billing? Reach out to our customer support team !
None of the above? Find out where to ask other questions here !
catower
Split this topic
December 5, 2019, 2:59am
2
How do I “Remove” items from a list, it’s never mentioned anywhere.
mtf
May 11, 2020, 12:02am
4
Have you checked the documentation for what built-ins and methods are available?
Is there an easy to way to remember when to use square brackets and when to use parenthesis? It seems arbitrary to me.
mtf
May 28, 2020, 11:11pm
6
Square brackets have three different uses/meanings.
[] => list object literal
[0] => list, str, or set subscript
['a'] => dict object key subscript
Parens have a number of uses/meanings.
(a + b) => grouping for precedence
foo(x) => parameter list of a function
foo(7) => argument list of a function call
(a, b, c) => tuple literal
To round this out, let’s also look at curly braces…
{'key': 'value'} => dict literal
{2, 5, 8, 11} => set literal
1 Like
Thanks. I don’t know what a lot of those terms mean, though.
mtf
June 5, 2020, 11:42pm
8
You will if you keep learning, which includes cycling back to review on a regular basis and using Google to look up terms.
dict literal py
If you tack on py
to your search phrase, the SERP will contain more links appropriate to Python.
rk45
July 10, 2020, 8:07pm
9
Can we enter any desired parameters in the parentheses for sort ?
Can you take everything done in the review section and put it into a function?
mtf
February 14, 2021, 12:03am
11
A function should have some specific purpose and predictable outcomes given particular inputs. The review section is expecting several outcomes, each of which is a different slice. In a sense it is like a function if we consider slicing a type of method, and the indices we supply as arguments.
Hi- Quick question here. Why does the review of this lesson say:
" * Generate a list using the range()
function."
The chapter is clear that range() returns a range object, that can be converted to a list with list(). This seems unnecessarily confusing as written.
If you use .pop() for checkpoints 2 and 3, it will give you the checkmark
However, when you do checkpoint 4 you will get an error even if you did it right.
I’d like to suggest removing the .pop() variation as a checkmark solution for checkpoints 2 and 3 because I was confused as to why my answer on checkpoint 4 was wrong.
1 Like
inventory_2_6=inventory[2:6] doubt in this line
Hi there,
I’m currently going through the last exercise in Lists
When I do the following:
sort_inventory = inventory.sort()
print(sort_inventory)
It produces “None”.
Why is that?
Please note, when in contrast I command the following:
sorted_inventory = sorted(inventory)
print(“Sorted inventory:”,sorted_inventory)
then it prints the sorted list without issues.
mtrtmk
September 24, 2022, 2:13pm
17
sorted
doesn’t change the original list, but returns a new sorted list.
.sort
sorts the list in-place (i.e. the original list is modified), but returns None
x = [3, 4, 1, 2, 5, 1, 2]
y = sorted(x)
print(x) // [3, 4, 1, 2, 5, 1, 2]
print(y) // [1, 1, 2, 2, 3, 4, 5]
x = [3, 4, 1, 2, 5, 1, 2]
y = x.sort()
print(x) // [1, 1, 2, 2, 3, 4, 5]
print(y) // None
Useful Documentation:
sorted
sort
Sorting HOW TO
1 Like
In the review section of review for python lists I keep recieving a error on step 4:
inventory_2_6 = inventory[2:6]
Does anyone know a solution to this step ?
It’s difficult to say. Please post your formatted code.