{"id":239,"date":"2023-03-30T14:42:52","date_gmt":"2023-03-30T14:42:52","guid":{"rendered":"https:\/\/joseph-t-gordon.tech\/?p=239"},"modified":"2023-06-26T14:24:09","modified_gmt":"2023-06-26T14:24:09","slug":"post-41-lists-in-lists-the-power-of-matrices","status":"publish","type":"post","link":"https:\/\/joseph-t-gordon.tech\/index.php\/2023\/03\/30\/post-41-lists-in-lists-the-power-of-matrices\/","title":{"rendered":"Post #41 (Python Programming) &#8211; Lists in lists, the power of matrices"},"content":{"rendered":"\n<p>In python believe it or not you actually have the power to put lists within lists. How would one do that? You can use the following code<\/p>\n\n\n\n<p>list = [1, 2, 3, 4, 5]<\/p>\n\n\n\n<p>for i in range(8):<\/p>\n\n\n\n<p>    list_2 = [1, 2, 3, 4, 5]<\/p>\n\n\n\n<p>    list.append(list_2)<\/p>\n\n\n\n<p>print(list)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The above code creates a list within a list, there&#8217;s an even easier way to quickly create a list at runtime. The first element is the value being stored in the list and the rest is the list you&#8217;re creating.<\/p>\n\n\n\n<p>list = [0.0 for x in range(8)]<\/p>\n\n\n\n<p>print(list)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>You can even nest lists this way as well, the following code creates a nested list, with 24 rows and 31 columns and assigns them all the value of &#8220;EMPTY&#8221; then prints the value stored in list index 24,31<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Hours_in_Month = [[&#8220;EMPTY&#8221; for i in range(31)] for x in range(24)]<\/p>\n\n\n\n<p>print(Hours_in_Month)<\/p>\n\n\n\n<p>print(Hours_in_Month[23][30])<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>You can even set values to specific indexes in your nested lists.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Hours_in_Month = [[&#8220;EMPTY&#8221; for i in range(31)] for x in range(24)]<\/p>\n\n\n\n<p>print(Hours_in_Month)<\/p>\n\n\n\n<p>print(Hours_in_Month[23][30])<\/p>\n\n\n\n<p>Hours_in_Month[0][0] = &#8220;Occupied&#8221;<\/p>\n\n\n\n<p>print(Hours_in_Month[0][0])<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In python believe it or not you actually have the power to put lists within lists. How would one do that? You can use the following code list = [1, 2, 3, 4, 5] for i in range(8): list_2 = [1, 2, 3, 4, 5] list.append(list_2) print(list) The above code creates a list within a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/posts\/239"}],"collection":[{"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/comments?post=239"}],"version-history":[{"count":2,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/posts\/239\/revisions"}],"predecessor-version":[{"id":325,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/posts\/239\/revisions\/325"}],"wp:attachment":[{"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/media?parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/categories?post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joseph-t-gordon.tech\/index.php\/wp-json\/wp\/v2\/tags?post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}