DEV Community

Durga Pokharel
Durga Pokharel

Posted on

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

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

#100DaysOfCode , day 6 #Python
* More about python Dictionary
* More about Loop
* Python program to find out even and odd numbers from list.

— Durga Pokharel (@mathdurga) December 29, 2020

Top comments (4)

otumianempire profile image
Michael Otu • 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

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

Yes. Thank you for the support.