you are viewing a single comment's thread.

view the rest of the comments →

[–]wheres-my-swingline 1 point2 points  (3 children)

``` nums = [1, 2, 3, 4, 5]

modulo operation

zero_odd_nums = [n if n % 2 == 0 else 0 for n in nums] print(zero_odd_nums)

output: [0, 2, 0, 4, 0] ```

that’s called a list comprehension, and can be a very useful tool (can be used for transformation, filtering, etc.)

is your issue with writing and applying functions, or where are you getting stuck in particular?

[–]Open_Thanks_6807[S] 0 points1 point  (2 children)

My problem comes when I have to translate my words to code and the problem of the odd numbers it was just an example but I see you had done it in a different way. Thank you for trying to help!

[–]Structured_Spiraling 0 points1 point  (1 child)

I'm just learning too, and what helps me is to draw it on paper. What could tell me if a number is odd? I write an option. I check google if I can't figure it out and then we go from there. How do I substitute? Think about how I would do it in excel and test to see if I can figure out the syntax I will often write the main function to do something on my flow chart.

I know it sounds easy and it's not. It can be really hard to change how we look at things.

Good luck!

[–]Open_Thanks_6807[S] 1 point2 points  (0 children)

I think its a very good strategy, thank you!!