The code below contains a dictionary called deck_of_cards that contains all 52 cards in a standard deck and their associated values. Remove all of the aces from deck_of_cards

https://www.codecademy.com/practice/tracks/learn-python-3/modules/learn-python3-dictionaries?redirect_url=%2Flearn%2Flearn-python-3

deck_of_cards = {'Ace of Spades': 1, '2 of Spades': 2, '3 of Spades': 3,  '4 of Spades': 4, '5 of Spades': 5, '6 of Spades': 6, '7 of Spades': 7, '8 of Spades': 8, '9 of Spades': 9, '10 of Spades': 10, 'Jack of Spades': 10, 'Queen of Spades': 10, 'King of Spades': 10, 'Ace of Diamonds': 1, '2 of Diamonds': 2, '3 of Diamonds': 3,  '4 of Diamonds': 4, '5 of Diamonds': 5, '6 of Diamonds': 6, '7 of Diamonds': 7, '8 of Diamonds': 8, '9 of Diamonds': 9, '10 of Diamonds': 10, 'Jack of Diamonds': 10, 'Queen of Diamonds': 10, 'King of Diamonds': 10, 'Ace of Hearts': 1, '2 of Hearts': 2, '3 of Hearts': 3,  '4 of Hearts': 4, '5 of Hearts': 5, '6 of Hearts': 6, '7 of Hearts': 7, '8 of Hearts': 8, '9 of Hearts': 9, '10 of Hearts': 10, 'Jack of Hearts': 10, 'Queen of Hearts': 10, 'King of Hearts': 10, 'Ace of Clubs': 1, '2 of Clubs': 2, '3 of Clubs': 3,  '4 of Clubs': 4, '5 of Clubs': 5, '6 of Clubs': 6, '7 of Clubs': 7, '8 of Clubs': 8, '9 of Clubs': 9, '10 of Clubs': 10, 'Jack of Clubs': 10, 'Queen of Clubs': 10, 'King of Clubs': 10} 

# Write your code below
for cards in deck_of_cards:
  if deck_of_cards.values() == 1:
    deck_of_cards.pop
return deck_of_cards

I do not understand why it wont pop off the ace since their values are always 1

There are several things wrong about that, consider how the different things you are using behave, pay special attention to input and output of functions, for example, what does a dict’s values method return? You’re comparing that to an integer, is it an integer? If not, then it’s not a meaningful comparison is it?
Do you need to iterate through the cards? Don’t you already know which the aces are?
What is the pop attribute of a dict? How is it used?

Before you write any code at all, make a decision about what needs to happen. Then match that to actions that the dict provides.

Being able to read and write to a key without searching through all keys is … kind of the whole point of a dict, so therefore you would not iterate through the cards, you would specify what to remove.

I suppose you technically can filter by value, but that’s a bit backwards with regard to what a dict provides, and I’d argue the “ace” part is in the key

.pop() is a method, calling a method requires parentheses.

also, you call .values() method on deck_of_cards, which means you get all the values in the dictionary:

dict_values([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10])

thank yoU! More thought needed on my part!

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.