{"id":49,"date":"2016-10-16T03:36:55","date_gmt":"2016-10-16T03:36:55","guid":{"rendered":"http:\/\/www.programminginpython.com\/2023\/03\/30\/python-program-to-separate-even-and-odd-numbers-in-a-list\/"},"modified":"2023-05-08T18:41:50","modified_gmt":"2023-05-08T18:41:50","slug":"python-program-separate-even-odd-numbers-lists","status":"publish","type":"post","link":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/","title":{"rendered":"Python Program to separate even and odd numbers in a list"},"content":{"rendered":"<p>Hello everyone! Welcome back to <a href=\"\/\" target=\"_blank\" rel=\"noopener\">Programming In Python<\/a>. Here in the post am going to add one more program which covers the Python data-type <code>list<\/code>. Here I will separate all the even and odd numbers from a list into two different lists.<\/p>\n<blockquote><p><span style=\"color: #0000ff;\">Master the basics of data analysis in Python. Expand your skillset by learning scientific computing with numpy.<\/span><\/p>\n<p><span style=\"color: #0000ff;\">Take the course on Introduction to Python on <span style=\"color: #ffd343;\"><a style=\"color: #ffd343;\" href=\"https:\/\/bit.ly\/join_datacamp\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">DataCamp<\/a><\/span> here <\/span><span style=\"color: #ffd343;\"><a style=\"color: #ffd343;\" href=\"https:\/\/bit.ly\/datacamp-intro-to-python\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https:\/\/bit.ly\/datacamp-intro-to-python<\/a><\/span><\/p><\/blockquote>\n<p> https:\/\/www.youtube.com\/watch?v=67pqIGhvGAo&#8221;]<\/p>\n<p style=\"text-align: center;\"><strong>You can also watch the video on YouTube <a href=\"https:\/\/www.youtube.com\/watch?v=67pqIGhvGAo\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/strong><\/p>\n<div class=\"visualize_iframe\">\n<h4 class=\"post_h4\">Separate even and odd numbers in a list \u2013 Code Visualization<\/h4>\n<p><iframe src=\"https:\/\/pythontutor.com\/iframe-embed.html#code=numbers%20%3D%20%5B%5D%0An%20%3D%20int%28input%28%22Enter%20number%20of%20elements%3A%20%5Ct%22%29%29%0Afor%20i%20in%20range%281,%20n%2B1%29%3A%0A%20%20%20%20allElements%20%3D%20int%28input%28%22Enter%20element%3A%22%29%29%0A%20%20%20%20numbers.append%28allElements%29%0A%0Aeven_lst%20%3D%20%5B%5D%0Aodd_lst%20%3D%20%5B%5D%0A%0Afor%20j%20in%20numbers%3A%0A%20%20%20%20if%20j%20%25%202%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20even_lst.append%28j%29%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20odd_lst.append%28j%29%0A%0Aprint%28%22Even%20numbers%20list%20%5Ct%22,%20even_lst%29%0Aprint%28%22Odd%20numbers%20list%20%5Ct%22,%20odd_lst%29&amp;codeDivHeight=400&amp;codeDivWidth=350&amp;cumulative=false&amp;curInstr=0&amp;heapPrimitives=false&amp;origin=opt-frontend.js&amp;py=3&amp;rawInputLstJSON=%5B%5D&amp;textReferences=false\" width=\"800\" height=\"500\" frameborder=\"0\"> <\/iframe><\/p>\n<\/div>\n<p class=\"extra_btn_para\"><span class=\"wdg\"> <a href=\"https:\/\/github.com\/avinashn\/programminginpython.com\/blob\/master\/even_odd_lists.py\" target=\"_blank\" rel=\"noopener noreferrer\"> <i class=\"fa fa-github fa-lg\"><\/i> Program on Github<\/a><\/span><\/p>\n<blockquote><p>Ad:<br \/>\n<span style=\"font-size: 18pt;\">Learn Python Programming Masterclass \u2013 <a href=\"https:\/\/bit.ly\/python-programming-masterclass\" target=\"_blank\" rel=\"noopener\">Enroll Now<\/a>.<\/span><br \/>\n<span style=\"font-size: 12px;\">Udemy<\/span><\/p><\/blockquote>\n<h4 class=\"post_h4\">Task:<\/h4>\n<p>Separate even and odd numbers from a list and add them to new lists.<\/p>\n<h4 class=\"post_h4\">Approach:<\/h4>\n<ul>\n<li>Read the input number asking for the length of the list using <span title=\"in Python 3\"><code>input()<\/code><\/span><\/li>\n<li>Initialize an empty list <code>numbers = []<\/code><\/li>\n<li>Read each number using a\u00a0<code>for loop<\/code><\/li>\n<li>In the for loop append each number to the list\u00a0<code>numbers<\/code><\/li>\n<li>Create another two empty lists <code>even_lst = []<\/code>\u00a0and <code>odd_lst = []<\/code><\/li>\n<li>Now run another for loop to check the numbers in the list are divided by 2 or not<\/li>\n<li>If the numbers are divided by 2, append those elements to <code>even_lst<\/code>else append those to <code>odd_lst<\/code><\/li>\n<li>Print both the <code>even_lst<\/code> and <code>odd_lst<\/code><\/li>\n<\/ul>\n<h4 class=\"post_h4\">Program:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">__author__ = 'Avinash'\r\n\r\nnumbers = []\r\nn = int(input(\"Enter number of elements: \\t\"))\r\nfor i in range(1, n+1):\r\n    allElements = int(input(\"Enter element:\"))\r\n    numbers.append(allElements)\r\n\r\neven_lst = []\r\nodd_lst = []\r\n\r\nfor j in numbers:\r\n    if j % 2 == 0:\r\n        even_lst.append(j)\r\n    else:\r\n        odd_lst.append(j)\r\n\r\nprint(\"Even numbers list \\t\", even_lst)\r\nprint(\"Odd numbers list \\t\", odd_lst)<\/pre>\n<p class=\"extra_btn_para\"><span class=\"wdg\"> <a href=\"https:\/\/github.com\/avinashn\/programminginpython.com\/blob\/master\/even_odd_lists.py\" target=\"_blank\" rel=\"noopener noreferrer\"> <i class=\"fa fa-github fa-lg\"><\/i> Program on GitHub<\/a><\/span><\/p>\n<h4 class=\"post_h4\">Output:<\/h4>\n<p><img decoding=\"async\" class=\"size-full wp-image-694 lazyload\" data-src=\"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/03\/separate_even_oddLists.png\" alt=\"Python Program to separate even and odd numbers in a list.\" width=\"764\" height=\"242\" data-srcset=\"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/03\/separate_even_oddLists.png 764w, https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/03\/separate_even_oddLists.png 300w\" data-sizes=\"(max-width: 640px) 100vw, 640px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 764px; --smush-placeholder-aspect-ratio: 764\/242;\" \/><\/p>\n<div class=\"course_suggestion\">\n<h5>Course Suggestion<\/h5>\n<p>Want to learn python with strong fundamentals? If yes, I strongly suggest you to take the course below.<br \/>\nCourse: <a href=\"https:\/\/www.eduonix.com\/flow-controls-fundamentals-of-programming-in-python\/UHJvZHVjdC04MDgwMDA=\" target=\"_blank\" rel=\"noopener noreferrer\">Fundamentals of Programming in Python<\/a><\/p>\n<p>For more programs on List datatype chek the posts below or <a href=\"https:\/\/www.programminginpython.com\/category\/data-structures\/lists\/\" target=\"_blank\" rel=\"noopener\">click here<\/a> for all programs related to lists.<\/p>\n<ul class=\"lcp_catlist\" id=\"lcp_instance_0\"><li><a href=\"https:\/\/www.programminginpython.com\/python-program-merge-concatenate-two-lists\/\">Python program to merge or concatenate two lists<\/a><\/li><li><a href=\"https:\/\/www.programminginpython.com\/python-biggest-smallest-3-numbers-lists\/\">Find the Biggest and Smallest of 3 numbers using lists in Python<\/a><\/li><li><a href=\"https:\/\/www.programminginpython.com\/python-lists-add-append-modify-remove-slice\/\">Python Lists \u2013 Add, Append, Modify, Remove, Slice<\/a><\/li><li><a href=\"https:\/\/www.programminginpython.com\/python-program-calculate-sum-elements-list\/\">Python program to calculate the sum of elements in a list<\/a><\/li><li><a href=\"https:\/\/www.programminginpython.com\/python-program-largest-smallest-number-list\/\">Python program to find the largest and smallest number in a list<\/a><\/li><li><a href=\"https:\/\/www.programminginpython.com\/find-union-two-lists-python\/\">How to find Union of two lists in Python<\/a><\/li><li class=\"current\"><a href=\"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/\">Python Program to separate even and odd numbers in a list<\/a><\/li><\/ul>\n<blockquote><p>Ad:<br \/>\n<span style=\"font-size: 18pt;\">Learn Python Programming Masterclass \u2013 <a href=\"https:\/\/bit.ly\/python-programming-masterclass\" target=\"_blank\" rel=\"noopener\">Enroll Now<\/a>.<\/span><br \/>\n<span style=\"font-size: 12px;\">Udemy<\/span><\/p><\/blockquote>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello everyone! Welcome back to programminginpython.com Here in the post am going to add one program which covers the python data-type list.\u00a0Here I will separate all the even and odd numbers from a list to &hellip;<\/p>\n","protected":false},"author":1,"featured_media":267,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,10,11],"tags":[23,20,32,26,21],"class_list":["post-49","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-basic-programs","category-data-structures","category-lists","tag-basic","tag-even","tag-lists","tag-numbers","tag-odd"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Program to separate even and odd numbers in a list<\/title>\n<meta name=\"description\" content=\"A simple python program to separate all the even and odd numbers from a list into two different lists of even and odd numbers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Program to separate even and odd numbers in a list\" \/>\n<meta property=\"og:description\" content=\"A simple python program to separate all the even and odd numbers from a list into two different lists of even and odd numbers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/\" \/>\n<meta property=\"og:site_name\" content=\"Programming In Python\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/programminginpython\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-16T03:36:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-08T18:41:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/03\/separate_even_oddLists_FB.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"AVINASH NETHALA\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@python_pip\" \/>\n<meta name=\"twitter:site\" content=\"@python_pip\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"AVINASH NETHALA\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Program to separate even and odd numbers in a list","description":"A simple python program to separate all the even and odd numbers from a list into two different lists of even and odd numbers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/","og_locale":"en_US","og_type":"article","og_title":"Python Program to separate even and odd numbers in a list","og_description":"A simple python program to separate all the even and odd numbers from a list into two different lists of even and odd numbers.","og_url":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/","og_site_name":"Programming In Python","article_publisher":"https:\/\/www.facebook.com\/programminginpython","article_published_time":"2016-10-16T03:36:55+00:00","article_modified_time":"2023-05-08T18:41:50+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/03\/separate_even_oddLists_FB.png","type":"image\/png"}],"author":"AVINASH NETHALA","twitter_card":"summary_large_image","twitter_creator":"@python_pip","twitter_site":"@python_pip","twitter_misc":{"Written by":"AVINASH NETHALA","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/#article","isPartOf":{"@id":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/"},"author":{"name":"AVINASH NETHALA","@id":"https:\/\/www.programminginpython.com\/#\/schema\/person\/9a3c14fe46d422ebf783ee61de1e788c"},"headline":"Python Program to separate even and odd numbers in a list","datePublished":"2016-10-16T03:36:55+00:00","dateModified":"2023-05-08T18:41:50+00:00","mainEntityOfPage":{"@id":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/"},"wordCount":270,"commentCount":0,"publisher":{"@id":"https:\/\/www.programminginpython.com\/#organization"},"image":{"@id":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/#primaryimage"},"thumbnailUrl":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/03\/separate_even_oddLists_WP1.png","keywords":["basic","even","lists","numbers","odd"],"articleSection":["Basic Programs","Data Structures","Lists"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/","url":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/","name":"Python Program to separate even and odd numbers in a list","isPartOf":{"@id":"https:\/\/www.programminginpython.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/#primaryimage"},"image":{"@id":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/#primaryimage"},"thumbnailUrl":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/03\/separate_even_oddLists_WP1.png","datePublished":"2016-10-16T03:36:55+00:00","dateModified":"2023-05-08T18:41:50+00:00","description":"A simple python program to separate all the even and odd numbers from a list into two different lists of even and odd numbers.","breadcrumb":{"@id":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/#primaryimage","url":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/03\/separate_even_oddLists_WP1.png","contentUrl":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/03\/separate_even_oddLists_WP1.png","width":1920,"height":400,"caption":"Python Program to separate even and odd numbers in a list"},{"@type":"BreadcrumbList","@id":"https:\/\/www.programminginpython.com\/python-program-separate-even-odd-numbers-lists\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.programminginpython.com\/"},{"@type":"ListItem","position":2,"name":"Python Program to separate even and odd numbers in a list"}]},{"@type":"WebSite","@id":"https:\/\/www.programminginpython.com\/#website","url":"https:\/\/www.programminginpython.com\/","name":"Programming In Python","description":"All About Python","publisher":{"@id":"https:\/\/www.programminginpython.com\/#organization"},"alternateName":"pip","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.programminginpython.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.programminginpython.com\/#organization","name":"Programming In Python","alternateName":"PIP","url":"https:\/\/www.programminginpython.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.programminginpython.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/pip_logo_500_500.png","contentUrl":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/04\/pip_logo_500_500.png","width":500,"height":500,"caption":"Programming In Python"},"image":{"@id":"https:\/\/www.programminginpython.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/programminginpython","https:\/\/x.com\/python_pip","https:\/\/www.youtube.com\/programminginpython","https:\/\/github.com\/avinashn\/programminginpython.com"]},{"@type":"Person","@id":"https:\/\/www.programminginpython.com\/#\/schema\/person\/9a3c14fe46d422ebf783ee61de1e788c","name":"AVINASH NETHALA","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.programminginpython.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ed52e7670d7db94820c7430d324103ccdecb16d86611d5b29064aa9ce25a958b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ed52e7670d7db94820c7430d324103ccdecb16d86611d5b29064aa9ce25a958b?s=96&d=mm&r=g","caption":"AVINASH NETHALA"},"sameAs":["https:\/\/www.programminginpython.com\/"],"url":"https:\/\/www.programminginpython.com\/author\/avinash\/"}]}},"jetpack_featured_media_url":"https:\/\/www.programminginpython.com\/wp-content\/uploads\/2023\/03\/separate_even_oddLists_WP1.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":4,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":696,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/posts\/49\/revisions\/696"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/media\/267"}],"wp:attachment":[{"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.programminginpython.com\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}