7.json 2.2 KB
Newer Older
每日一练社区's avatar
test  
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{
   "question_id": 7455269,
   "question_title": "列表奇偶拆分",
   "question_content": "<p>【问题描述】\n输入一个列表&#xff0c;包含若干个整数&#xff08;允许为空&#xff09;&#xff0c;然后将其中的奇数和偶数单独放置在一个列表中&#xff0c;保持原有顺序\n【输入形式】\n【输出形式】\n分两行输出&#xff0c;第一行输出偶数序列&#xff0c;第二行输出奇数序列\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如果奇偶拆分后&#xff0c;奇数列表&#xff0c;或者偶数列表为空&#xff0c;请直接输出NONE表示\n </p>",
   "difficulty": "简单",
   "answer_id": 53438879,
   "answer_content": "<pre>\n<code class=\"language-python\">x &#61; input()\nx1 &#61; x.strip(&#39;[]&#39;)  # 去除输入列表字符串的[]\nx2 &#61; x1.split(&#34;,&#34;)  # 将字符串变为列表\na &#61; []\nb &#61; []\nfor i in x2:\n    if int(i) % 2 &#61;&#61; 0:\n        a.append(i)\n    else:\n        b.append(i)\nif a &#61;&#61; []:\n    print(&#34;NONE&#34;)\nelse:\n    print(a)\nif b &#61;&#61; []:\n    print(&#34;NONE&#34;)\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
}