{ "question_id": 7455269, "question_title": "列表奇偶拆分", "question_content": "<p>【问题描述】\n输入一个列表,包含若干个整数(允许为空),然后将其中的奇数和偶数单独放置在一个列表中,保持原有顺序\n【输入形式】\n【输出形式】\n分两行输出,第一行输出偶数序列,第二行输出奇数序列\n【样例输入1】\n[48,82,47,54,55,57,27,73,86,14]\n【样例输出1】\n48, 82, 54, 86, 14\n47, 55, 57, 27, 73\n【样例输入2】\n[10, 22, 40]\n【样例输出2】\n10, 22, 40\nNONE\n【样例说明】\n如果奇偶拆分后,奇数列表,或者偶数列表为空,请直接输出NONE表示\n </p>", "difficulty": "简单", "answer_id": 53438879, "answer_content": "<pre>\n<code class=\"language-python\">x = input()\nx1 = x.strip('[]') # 去除输入列表字符串的[]\nx2 = x1.split(",") # 将字符串变为列表\na = []\nb = []\nfor i in x2:\n if int(i) % 2 == 0:\n a.append(i)\n else:\n b.append(i)\nif a == []:\n print("NONE")\nelse:\n print(a)\nif b == []:\n print("NONE")\nelse:\n print(b)</code></pre>\n\n<p> </p>\n\n<p><img alt=\"\" src=\"https://img-ask.csdnimg.cn/upload/1624271862835.png\" style=\"float:left\" /></p>\n\n<p> </p>\n\n<p> </p>\n\n<p> </p>\n\n<p> </p>\n\n<p> </p>\n\n<p><img alt=\"\" src=\"https://img-ask.csdnimg.cn/upload/1624271893188.png\" style=\"float:left\" /></p>\n", "tag_name": "python", "python": "x = input()\nx1 = x.strip('[]') \nx2 = x1.split(\",\") \na = []\nb = []\nfor i in x2:\n\tif int(i) % 2 == 0:\n\t\ta.append(i)\n\telse:\n\t\tb.append(i)\nif a == []:\n\tprint(\"NONE\")\nelse:\n\tprint(a)\nif b == []:\n\tprint(\"NONE\")\nelse:\n\tprint(b)", "topic_link": "https://bbs.csdn.net/topics/600470297", "status": 1, "keywords": "散列表,散列表,算法中阶,数据结构", "license": "csdn.net", "notebook": { "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/7.ipynb?type=file" }, "notebook_enable": 1 }