DEV Community


Day 6 of 100DaysOfCode: Python Code to Find Even and Odd Numbers From List

Durga Pokharel
A mathematics student learning to code.
・1 min read

This is my 6th day of 100daysofcoding. I continue to learn from Coursera Python Data Structure course and also did some assignments. I tired to write code to find even and odd numbers from list. My code is right below.
My Solution

  • Create a empty dictionary
  • Give list of numbers
  • Loop through each numbers and find out even numbers and keep it in even list similarly find odd numbers and keep it in odd list.
my_dict = {}
numbers = list(range(1,11))
even = []
odd = []
for n in numbers:
    if n % 2 == 0:

my_dict["odd"] = odd
my_dict["even"] = even
Enter fullscreen mode Exit fullscreen mode

Discussion (4)

otumianempire profile image
Otu Michael • Edited

Code looks fun. I am sure you have come across the concept of functions, modules and how to use return. Try using functions and add a unit test for the function. You can have a separate file for testing or keep the code (function) in the same file as the test.

iamdurga profile image
Durga Pokharel Author

This is great idea. Will try it. Thanks

aabiseverywhere profile image
Aabishkar Wagle

Nice. Keep it up. May be you can try implementing more advance data structures in coming days. 😀

iamdurga profile image
Durga Pokharel Author

Yes. Thank you for the support.