Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building an Expense Tracker - Step 13 - map object print out not explained #53135

Closed
ChiaraGambone opened this issue Jan 11, 2024 · 8 comments · Fixed by #54624
Closed

Building an Expense Tracker - Step 13 - map object print out not explained #53135

ChiaraGambone opened this issue Jan 11, 2024 · 8 comments · Fixed by #54624
Labels
new python course scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. status: discussing Under discussion threads. Closed as stale after 60 days of inactivity. type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc.

Comments

@ChiaraGambone
Copy link

ChiaraGambone commented Jan 11, 2024

Describe the Issue

Step 13 teaches the use of the map() function with the lambda function test = lambda x: x * 2 on an array of integers.
The exercise console doesn't show the result of this operation, but instead displays

>>> <map object at 0x10fe398>

Affected Page

https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-lambda-functions-by-building-an-expense-tracker/step-13

Your code

def add_expense(expenses, amount, category):
    expenses.append({'amount': amount, 'category': category})
    
def print_expenses(expenses):
    for expense in expenses:
        print(f'Amount: {expense["amount"]}, Category: {expense["category"]}')

def total_expenses(expenses):
    pass
    
test = lambda x: x * 2
print(map(test, [2, 3, 5, 8]))

expenses = []

Expected behavior

I expect I should see the result of this operation in the console.

Screenshots

nucTLRXdar

System

  • Device: Laptop
  • OS: Windows 11
  • Browser: Firefox
  • Version: 121.0.1 (64-bit)

Additional context

No response

@ChiaraGambone ChiaraGambone added scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. status: waiting triage This issue needs help from moderators and users to reproduce and confirm its validity and fix. type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc. labels Jan 11, 2024
@ilenia-magoni
Copy link
Contributor

that's correct, it outputs a map object, that's the output on the console. One would need to use list() or tuple() on the map object before printing to see the elements. This step could be changed maybe to show the elements on the console with those.

@gikf
Copy link
Member

gikf commented Jan 12, 2024

Maybe better would be wrapping it in the list() in a new step? I'm not sure if this was mentioned elsewhere, or is it later, but that would be good point to briefly explain why map or filter don't simply return changed lists.

@gikf gikf changed the title Building an Expense Tracker Step 13 Missing map lambda console output Building an Expense Tracker - Step 13 - map object print out not explained Jan 12, 2024
@Dario-DC
Copy link
Contributor

Maybe better would be wrapping it in the list() in a new step? I'm not sure if this was mentioned elsewhere, or is it later, but that would be good point to briefly explain why map or filter don't simply return changed lists.

Adding one o two steps to expand on map and filter and show a readable output would be great.

@techlism
Copy link

I am trying to work on this.. one simple solution is make it a list or iterate over using a loop.
What should be implemented ?

@lasjorg
Copy link
Contributor

lasjorg commented Jan 12, 2024

Why are we even asking them to print that?

This is also different between Python 2 and Python 3. So maybe that is worth mentioning?

https://www.learnpython.org/en/Map%2C_Filter%2C_Reduce

@ChiaraGambone
Copy link
Author

that's correct, it outputs a map object, that's the output on the console. One would need to use list() or tuple() on the map object before printing to see the elements. This step could be changed maybe to show the elements on the console with those.

thank you for the explanation, makes sense but since the step explicitly tells you to print the result, it did seem like a console bug.
As a learner, i think it only makes sense that this is explained properly then

@lasjorg
Copy link
Contributor

lasjorg commented Jan 12, 2024

The way it is written makes me think it was originally written for Python 2 as that would have printed the list.

@techlism
Copy link

Okay now since we know that it is python3 and there was a need of printing. So what should be done.

@Sembauke Sembauke added status: discussing Under discussion threads. Closed as stale after 60 days of inactivity. and removed status: waiting triage This issue needs help from moderators and users to reproduce and confirm its validity and fix. labels Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new python course scope: curriculum Lessons, Challenges, Projects and other Curricular Content in curriculum directory. status: discussing Under discussion threads. Closed as stale after 60 days of inactivity. type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants