FAQ: Collections - Review of Specialized Containers

This community-built FAQ covers the “Review of Specialized Containers” exercise from the lesson “Collections”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Intermediate Python 3

FAQs on the exercise Review of Specialized Containers

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

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!

I’m doing the final part of the lesson of the collections. This is my code:

from collections import deque, namedtuple

overstock_items = [['shirt_103985', 15.99],

                    ['pants_906841', 19.99],

                    ['pants_765321', 15.99],

                    ['shoes_948059', 29.99],

                    ['shoes_356864', 9.99],

                    ['shirt_865327', 10.99],

                    ['shorts_086853', 9.99],

                    ['pants_267953', 21.99],

                    ['dress_976264', 32.99],

                    ['shoes_135786', 17.99],

                    ['skirt_196543', 12.99],

                    ['jacket_976535', 26.99],

                    ['pants_086367', 30.99],

                    ['dress_357896', 29.99],

                    ['shoes_157895', 14.99]]

# Write your code below!

split_prices = deque()

ClothesBundle = namedtuple("ClothesBundle", ["bundle_items", "bundle_price"])

bundles = []

promoted_bundles = []

# sorting prices in split_prices

for item in overstock_items:

  if item[-1] > 20:

    split_prices.appendleft(item)

  else:

    split_prices.append(item)

# loop to make bundles

while len(split_prices) >= 5:

  price = 0

  items = []

  for i in range(3):

    t_price = split_prices.pop()

    items.append(t_price[0])

    price += t_price[-1]

  for i in range(2):

    t_price = split_prices.popleft()

    items.append(t_price[0])

    price += t_price[-1]

  bundles.append(ClothesBundle(items, price))

# check if bundle is over $100

for bundle in bundles:

  if bundle.bundle_price > 100:

    promoted_bundles.append(bundle)

# printing the result

print(promoted_bundles)

for bundle in promoted_bundles:

  print(bundle)

Whenever I run this code on the last step I get the error: Did you print out promoted_bundles? When I’m clearly printing out the promoted bundles. I’ll have to copy the solution to progress, but could any of you tell if my code is wrong?

This is the link to the lesson: https://www.codecademy.com/courses/learn-intermediate-python-3/lessons/collections-python/exercises/review-of-specialized-containers-python

1 Like

Hi all,

Is there a more elegant way to iterate through the popleft() and pop() to create the bundle_list that Checkpoint 4 requests?
Here’s my code but I think it’s a bit lengthy. Also I like it better when the bundle_items only includes just the items and not the whole [item, price]

bundles = []
while len(split_prices) >= 5:
  expensive = []
  for i in range(2):
    expensive.append(split_prices.popleft())
  cheap = []
  for i in range(3):
    cheap.append(split_prices.pop())
  bundle = expensive + cheap
  item = [i[0] for i in bundle]
  price = sum(b[1] for b in bundle)
  bundles.append(ClothesBundle(item, price))
print(bundles)

Thank you everyone!

for item in overstock_items:
  if item[1] > 20:
    split_prices.appendleft(item)
  else:
    split_prices.append(item)

for item in split_prices:
  print(item)

This is my code for step 1. Here’s the print output:

Output-only Terminal
Output:
[‘dress_357896’, 29.99]
[‘pants_086367’, 30.99]
[‘jacket_976535’, 26.99]
[‘dress_976264’, 32.99]
[‘pants_267953’, 21.99]
[‘shoes_948059’, 29.99]
[‘shirt_103985’, 15.99]
[‘pants_906841’, 19.99]
[‘pants_765321’, 15.99]
[‘shoes_356864’, 9.99]
[‘shirt_865327’, 10.99]
[‘shorts_086853’, 9.99]
[‘shoes_135786’, 17.99]
[‘skirt_196543’, 12.99]
[‘shoes_157895’, 14.99]

I keep getting the error:

split_prices did not contain the clothes data in the correct order. Make sure to append items greater than 20 dollars to the front of split_prices and items with less than 20 dollars to the back of split_prices. For example, the first item should be: ['dress_357896', 29.99] since that is the last item over 20 dollars in overstock_items.

I have literally gone through the print output by hand and everything is in the right order. Additionally, my code is exactly the same as someone else’s loop above (except that they used index -1, but this shouldn’t make a difference). WHY am I still getting this error? I am losing my mind. Is this a bug?

ETA: The AI learning assistant even says there’s nothing wrong with my code.

Edit 2: I finally figured it out. The error checking didn’t like that I was iterating over the list to print it instead of just printing it directly. The error I was given had NOTHING to do with the supposed “problem,” which wasn’t a problem at all! I’m really upset at the lesson quality in Codecademy. You need better QA.