Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Challenge: Refactor to Pythonic Style | Pythonic Best Practices
Code Quality and Refactoring in Python

bookChallenge: Refactor to Pythonic Style

In this challenge, you will refactor a piece of code to use more Pythonic constructs. Your goal is to rewrite the provided code to make use of list comprehensions and built-in functions, replacing manual loops and unnecessary temporary variables. This exercise will help you practice writing code that is concise, readable, and takes full advantage of Python's strengths.

Aufgabe

Swipe to start coding

Refactor the function get_even_squares to use Pythonic idioms.

  • Replace the explicit loop and manual list appending with a list comprehension.
  • Use only built-in functions and constructs.

Lösung

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 4
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you provide the code that needs to be refactored?

What are some examples of Pythonic constructs I should use?

Can you show me an example of a refactored code using list comprehensions?

close

Awesome!

Completion rate improved to 5.26

bookChallenge: Refactor to Pythonic Style

Swipe um das Menü anzuzeigen

In this challenge, you will refactor a piece of code to use more Pythonic constructs. Your goal is to rewrite the provided code to make use of list comprehensions and built-in functions, replacing manual loops and unnecessary temporary variables. This exercise will help you practice writing code that is concise, readable, and takes full advantage of Python's strengths.

Aufgabe

Swipe to start coding

Refactor the function get_even_squares to use Pythonic idioms.

  • Replace the explicit loop and manual list appending with a list comprehension.
  • Use only built-in functions and constructs.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 4
single

single

some-alt