Closed BethanyG closed 2 years ago
I'd like to work on this. Thanks!
Btw, I noticed we already have an exercise for this: https://github.com/exercism/elixir/tree/main/exercises/concept/secrets It's in combination with bit manipulation tho (which should also be taught in Python). So should I use that or make a new one?
Hi @Steffan153 - Happy to have you work on it! 🎉 Unfortunately, bit manipulation is not a prerequisite for this exercise, and this is probably not the place to introduce it. We have an exercise planned, but it's not on our priority list right now. You are more than welcome to fork the Elixir exercise and adapt it -- but I think we need to leave the bit manipulation out.
Also -- be warned: unlike functional-first programming languages, Python's lambdas are quite limited. They can only contain code that is computable as a single expression, and be written on a single line. They can't contain statements.
It is customary to only use them in very constrained situations -- most often as sort keys, or as arguments to map()
, filter()
and functools.reduce()
. They also execute in their own frame, which makes error handling and stack traces more effort, and often slows code execution if you're not careful. But I'll stop now ... and let you do the write-up! 😉 😜
The documentation links at the top are up-to-date, but the ones in the body are not. I will update those shortly. Let me know here (or in our Slack channel if you are there) if you have any questions or issues.
Is there a link to the exercise? Also, I think the Secrets exercise will work fine, we just need to remove the 2 bitwise functions.
Apologies - I wasn't very clear in my language above (I corrected it). I meant that you are more than welcome to adapt the Elixir exercise. We don't have anything (yet) for bitwise operators/manipulation.
Please keep in mind that one of the major uses of lambda
in Python is as a key expression
for things like sort()
, sorted()
, min()
and max()
-- so you'll want to add those use cases in, but yes -- I think Secrets
is a good place to start. 😄
BTW, are you sure the top links are 7p to date? Some of them 404 on me.
Looks like they moved tasks
under product
😱 It should be updated now...and the others all work for me. LMK if you find anything else, tho. 😄
Alternatively, if the website links don't work for some reason, the same documents can be found under our exercism docs repo.
This issue has been automatically marked as abandoned 🏚
because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as abandoned 🏚
because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Closed in favor of #3105 & #3106.
This issue describes how to implement the
anonymous-functions
(lambdas) concept exercise for the python track.Getting started
Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
Goal
This concept exercise is meant to teach an understanding/creation/use of
lambda
oranonymous functions
in python.Learning objectives
anonymous function
is, and how to create onelambda
function argument
flavors withlambda
lambdas
and Pythons "regular"functions
lambda
lambdas
, and when to avoid themlambdas
askey functions
in other situations such assort()
,sorted()
,min()
, andmax()
lambda
via IIFE (immediately invoked function expression)lambdas
Out of scope
comprehensions
comprehensions
inlambdas
decorator
on alambda
functools
(this will get its own exercise)generators
map()
,filter()
, andreduce()
(these will get their own exercise)assignment expression
or "walrus" operator (:=
) in alambda
Concepts
anonymous-functions
lambdas
functions
,higher-order functions
functions as arguments
functions as returns
nested funcitons
Prerequisites
These are the concepts/concept exercises the student needs to complete/understand before solving this concept exercise.
basics
booleans
comparisons
dicts
dict-methods
functions
function-arguments
higher-order functions
iteration
lists
list-methods
numbers
sequences
sets
strings
string-methods
tuples
Resources to refer to
Python Docs: Defining Functions
Python Docs Tutorial: Lambda Expressions
Functions as Objects in Python
Composing Programs: Higher-Order Functions
Learn by Example: Python Lambda Function
Real Python: How to Use Python Lambda Fuctions
Trey Hunner: Overusing Lambda expressions in Python
Hints
For more information on writing hints see hints
links.json
For more information, see concept links file
concepts/links.json
file, if it doesn't already exist.links.json
document.Concept Description
Please see the following for more details on these files: concepts & concept exercises
Concept
about.md
Concept file/issue: anonymous-functions directory with stubbed files -- Content is TBD and should be completed as part of this exercise creation.
Anonymous-functions
concept write-ups and associated files can be included in the PR for this issue, or as a separate PR linked to this issue.For more information, see Concept
about.md
Concept
introduction.md
For more information, see Concept
introduction.md
Exercise
introduction.md
For more information, see Exercise
introduction.md
Test-runner
No changes required to the Python Test Runner at this time.
Representer
No changes required to the Python Representer at this time.
Analyzer
No changes required to the Python Analyzer at this time.
Exercise Metadata - Track
For more information on concept exercises and formatting for the Python track
config.json
, please see concept exercise metadata. The trackconfig.json
file can be found in the root of thisPython
repo.You can use the below for the exercise UUID. You can also generate a new one via exercism configlet, uuidgenerator.net, or any other favorite method. The UUID must be a valid V4 UUID.
Exercise Metadata Files Under
.meta/config.json
For more information on exercise
.meta/
files and formatting, see concept exercise metadata files.meta/config.json
- see this link for the fields and formatting of this file..meta/design.md
- see this link for the formatting of this file. Please use the Goal, Learning Objectives,Concepts, Prerequisites and , Out of Scope sections from this issue.Implementation Notes
Code in the
.meta/examplar.py
file should only use syntax & concepts introduced in this exercise or one of its prerequisite exercises. We run all ourexamplar.py
files through PyLint, but do not require module docstrings. We do require function docstrings similar to PEP257. See this concept exerciseexemplar.py
for an example.Please do not use comprehensions, generator expressions, or other syntax not previously covered. Please also follow PEP8 guidelines.
In General, tests should be written using
unittest.TestCase
and the test file should be named<EXERCISE-NAME>_test.py
.PyTest custom mark
to link test cases to exercise task numbers.unittest.subtest
to parameterize test input where/when needed. Here is an example testfile that shows all three of these in action.While we do use PyTest as our test runner and for some implementation tests, please check with a maintainer before using a PyTest test method, fixture, or feature.
Our markdown and JSON files are checked against prettier . We recommend setting prettier up locally and running it prior to submitting your PR to avoid any CI errors.
Help
If you have any questions while implementing the exercise, please post the questions as comments in this issue, or contact one of the maintainers on our Slack channel.