{"id":21351952,"url":"https://github.com/hygull/stkovrflw","last_synced_at":"2026-05-09T09:17:40.279Z","repository":{"id":41948115,"uuid":"132311923","full_name":"hygull/stkovrflw","owner":"hygull","description":"A project containing the code examples related to different kind of questions and their detailed solutions (that I solved on Stackoverflow). ","archived":false,"fork":false,"pushed_at":"2024-02-07T20:13:31.000Z","size":66140,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T04:41:47.525Z","etag":null,"topics":["javascript","markdown","pylatex","python2","python3"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hygull.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-06T06:10:14.000Z","updated_at":"2022-03-19T17:46:58.000Z","dependencies_parsed_at":"2024-11-22T03:22:03.530Z","dependency_job_id":null,"html_url":"https://github.com/hygull/stkovrflw","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hygull/stkovrflw","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hygull%2Fstkovrflw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hygull%2Fstkovrflw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hygull%2Fstkovrflw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hygull%2Fstkovrflw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hygull","download_url":"https://codeload.github.com/hygull/stkovrflw/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hygull%2Fstkovrflw/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260451178,"owners_count":23011220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","markdown","pylatex","python2","python3"],"created_at":"2024-11-22T03:11:57.919Z","updated_at":"2026-05-09T09:17:35.241Z","avatar_url":"https://github.com/hygull.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stkovrflw\nA project containing the code examples related to different kind of questions and their detailed solutions (that I solved on Stackoverflow). \n\n### 1\n\n\u003e [https://stackoverflow.com/questions/56015083/javascr...](https://stackoverflow.com/questions/56015083/javascript-how-to-create-an-array-with-x-number-of-properties-from-another-ar/56015499#56015499)\n\n```javascript\n// https://stackoverflow.com/questions/56015083/javascript-how-to-create-an-array-with-x-number-of-properties-from-another-ar/56015499#56015499\n// Solved on 6 May 2019\n\nfunction getNewArray(arr) {\n\tlet newArr = [];\n\n\tif(arr.length) {\n\t\tlet keys = [\"0-1s\", \"1-2s\"];\n\t\t\n\t\tnewArr = keys.map((key) =\u003e {\n\t\t\tlet newObj = {}\n\t\t\tconsole.log(newObj, key)\n\n\t\t\tfor(let obj of arr) {\t\t\t\t\n\t\t\t\tif(newObj[\"time\"] === undefined) {\n\t\t\t\t\tnewObj[\"time\"] = key\n\t\t\t\t}\n\t\t\t\tnewObj[obj[\"country\"]] = obj[key]\n\t\t\t}\n\n\t\t\treturn newObj\n\t\t})\n\t} \n\n\treturn newArr\n}\n\n\nfunction test() {\n\tlet arr = [{\n\t\t   \"0-1s\": 6,\n\t\t   \"1-2s\": 2,\n\t\t   country: \"us\"\n\t\t}, {\n\t\t   \"0-1s\": 1,\n\t\t   \"1-2s\": 4,\n\t\t   country: \"ja\"\n\t\t}, {\n\t\t   \"0-1s\": 3,\n\t\t   \"1-2s\": 9,\n\t\t   country: \"ca\"\n\t\t}]\n\n\tlet newArr = getNewArray(arr)\n\tconsole.log(newArr)\n\t/*\n\t\t[ { time: '0-1s', us: 6, ja: 1, ca: 3 },\n\t  { time: '1-2s', us: 2, ja: 4, ca: 9 } ]\n\t*/\n\n\t/* --- Pretty printing --- */\n\tconsole.log(JSON.stringify(newArr, null, 4))\n\t/*\n\t\t[\n\t\t    {\n\t\t        \"time\": \"0-1s\",\n\t\t        \"us\": 6,\n\t\t        \"ja\": 1,\n\t\t        \"ca\": 3\n\t\t    },\n\t\t    {\n\t\t        \"time\": \"1-2s\",\n\t\t        \"us\": 2,\n\t\t        \"ja\": 4,\n\t\t        \"ca\": 9\n\t\t    }\n\t\t]\n\t*/\n}\n\n//\ntest()\n```\n\n### 2\n\n\u003e [https://stackoverflow.com/questions/56095946/how-do-i-convert-a-map-object-to-list-and-also-assign-to-a-variable/56096030#56096030](https://stackoverflow.com/questions/56095946/how-do-i-convert-a-map-object-to-list-and-also-assign-to-a-variable/56096030#56096030)\n\nOnce you will \n\n+ learn/know about how Python generator works\n\n+ write/create your own generators\n\nyou will easily figure out this problem (looks strange but very useful and simple).\n\n\u003e Thanks to **yield** keyword \u0026 **StopIteration** exception \u0026 some magic methods as these play great roles in writing our own generator.\n\n```python\nPython 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 03:02:14) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e \n\u003e\u003e\u003e arr = [1729, 67, 92]\n\u003e\u003e\u003e gen = map(str, arr)\n\u003e\u003e\u003e \n\u003e\u003e\u003e # 1st item\n... \n\u003e\u003e\u003e gen.__next__()\n'1729'\n\u003e\u003e\u003e \n\u003e\u003e\u003e # 2nd item\n... \n\u003e\u003e\u003e gen.__next__()\n'67'\n\u003e\u003e\u003e \n\u003e\u003e\u003e # 3rd item\n... \n\u003e\u003e\u003e gen.__next__()\n'92'\n\u003e\u003e\u003e \n\u003e\u003e\u003e # This will not work (Exception beacause no more items are in generator, over)\n... \n\u003e\u003e\u003e gen.__next__()\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nStopIteration\n\u003e\u003e\u003e \n```\n\nSo if you will focus on below kind of examples, you will be confused (1st time).\n\n```python\n\u003e\u003e\u003e arr2 = list(gen)\n\u003e\u003e\u003e arr2\n['1729', '67', '92']\n\u003e\u003e\u003e\n\u003e\u003e\u003e # Generator has already been iterated, so no more items\n...\n\u003e\u003e\u003e gen.__next__()\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nStopIteration\n\u003e\u003e\u003e\n\u003e\u003e\u003e arr2 = list(gen)\n\u003e\u003e\u003e arr2\n[]\n\u003e\u003e\u003e \n```\n\nJust for references, have a look at below links.\n\n+ https://www.programiz.com/python-programming/generator\n\n+ https://dbader.org/blog/python-generator-expressions","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhygull%2Fstkovrflw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhygull%2Fstkovrflw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhygull%2Fstkovrflw/lists"}