{"id":4992,"date":"2019-08-14T13:35:45","date_gmt":"2019-08-14T08:05:45","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=4992"},"modified":"2019-08-22T09:34:41","modified_gmt":"2019-08-22T04:04:41","slug":"essential-things-to-know-about-list-data-structure-in-python","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/essential-things-to-know-about-list-data-structure-in-python\/","title":{"rendered":"Essential things to know about List data structure in  python"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Essential things to know about List data structure in  python<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">DATE : 22\/08\/2019<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">INTRODUCTION<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">     In python, the list is defined as a collection of items separated by a comma within the square bracket.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">which is best to use when we want to work with different values.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">LIST<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>one of the main thing about a list is that items in a list need not be of the same type.<\/li><li>which is used to store multiple data at the same time.<\/li><li>Lists are mutable,  they can be altered even after their creation.<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">LIST OPERATIONS:<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">Access the list:<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">list = [\"Math\",0,1,2,4,23,56,32,234,437,987,\"physics\",\"chemistry\",1997,2008]\n\n#print the list in python\n\nprint(list);\n\n#access the list items using index\n\nprint \"print the first value: \", list[0]\n\n#access the items using slice operator\n\nprint \"list[5:12]: \", list[5:12]\n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">RESULT:<\/p>\n\n\n\n<ul class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img fetchpriority=\"high\" decoding=\"async\" width=\"602\" height=\"100\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/accesslist.png\" alt=\"\" data-id=\"4995\" data-link=\"https:\/\/pheonixsolutions.com\/blog\/?attachment_id=4995\" class=\"wp-image-4995\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/accesslist.png 602w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/accesslist-300x50.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/figure><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">APPEND THE LIST<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#append operations\n\nlist = [\"Math\",0,1,2,4,23,56,32,234,437,987,\"physics\",\"chemistry\",1997,2008]\n\n#append will add the in value end of the list\nlist.append(\"mango\")\n\nprint(list);\n\n#append the one list with another list\nlist1 = [\"apple\", \"orange\", \"banana\"]\n\n#list1 append with the list\nlist.append(list1)\n\nprint(list)\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">RESULT:<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"893\" height=\"136\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/APPEND.png\" alt=\"\" class=\"wp-image-4997\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/APPEND.png 893w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/APPEND-300x46.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/APPEND-768x117.png 768w\" sizes=\"(max-width: 893px) 100vw, 893px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">LIST COUNT<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#return the number of times the value \"physics\" appears int the list\nlist = [\"Math\",0,1,2,4,23,56,32,234,437,987,\"physics\",\"chemistry\",1997,2008,\"physics\"]\n\nx = list.count(\"physics\")\n\nprint(x)\n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">RESULT<\/p>\n\n\n\n<ul class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img decoding=\"async\" width=\"589\" height=\"92\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/COUNT.png\" alt=\"\" data-id=\"4998\" data-link=\"https:\/\/pheonixsolutions.com\/blog\/?attachment_id=4998\" class=\"wp-image-4998\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/COUNT.png 589w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/COUNT-300x47.png 300w\" sizes=\"(max-width: 589px) 100vw, 589px\" \/><\/figure><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">EXTEND THE LIST<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">list1 = [\"apple\", \"orange\", \"banana\"]\nlist2 = [\"mango\"]\n\n\nlist1.extend(list2)\n\nprint(list1)\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">RESULT<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"106\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/extend.png\" alt=\"\" class=\"wp-image-4999\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/extend.png 601w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/extend-300x53.png 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">INSERT VALUE TO LIST<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#insert the value to particular position\nlist = [\"Math\",0,1,2,4,23,56,32,234,437,987,\"physics\",\"chemistry\",1997,2008,\"physics\"]\n\nlist.insert(1, \"english\")\n\nprint(list)\n<\/pre>\n\n\n\n<ul class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"779\" height=\"118\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/insert.png\" alt=\"\" data-id=\"5000\" data-link=\"https:\/\/pheonixsolutions.com\/blog\/?attachment_id=5000\" class=\"wp-image-5000\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/insert.png 779w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/insert-300x45.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/insert-768x116.png 768w\" sizes=\"(max-width: 779px) 100vw, 779px\" \/><\/figure><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">POP THE LIST<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#pop(delete) the list\nlist = [\"Math\",0,1,2,4,23,56,32,234,437,987,\"physics\",\"chemistry\",1997,2008,\"physics\"]\n\n\nlist.pop(1)\n\nprint(list)\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">RESULT<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"78\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/pop.png\" alt=\"\" class=\"wp-image-5001\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/pop.png 666w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/pop-300x35.png 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">REMOVE<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#remove the value\nlist = [\"Math\",0,1,2,4,23,56,32,234,437,987,\"physics\",\"chemistry\",1997,2008,\"physics\"]\n\nlist.remove(23)\n\nprint(list)\n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">RESULT<\/p>\n\n\n\n<ul class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-4 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"679\" height=\"96\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/remove.png\" alt=\"\" data-id=\"5002\" data-link=\"https:\/\/pheonixsolutions.com\/blog\/?attachment_id=5002\" class=\"wp-image-5002\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/remove.png 679w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/remove-300x42.png 300w\" sizes=\"(max-width: 679px) 100vw, 679px\" \/><\/figure><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">REVERSE<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#reverse the list \nlist = [\"Math\",0,1,2,4,23,56,32,234,437,987,\"physics\",\"chemistry\",1997,2008,\"physics\"]\n\nlist.reverse()\n\nprint(list)\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">RESULT<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"716\" height=\"91\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/reverse.png\" alt=\"\" class=\"wp-image-5003\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/reverse.png 716w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/reverse-300x38.png 300w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">SORT<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#sort the list\nlist = [1997,0,1,2,4,2018,23,234,56,32,437,987,2008]\nlist.sort()\n\nprint(list)\n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">RESULT<\/p>\n\n\n\n<ul class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-5 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"84\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/SORT.png\" alt=\"\" data-id=\"5004\" data-link=\"https:\/\/pheonixsolutions.com\/blog\/?attachment_id=5004\" class=\"wp-image-5004\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/SORT.png 586w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/08\/SORT-300x43.png 300w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/figure><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for using&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/\">pheonix solutions<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You find this tutorial helpful? Share with your friends to keep it alive.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Essential things to know about List data structure in python DATE : 22\/08\/2019 INTRODUCTION In python, the list is defined [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[600,706,292],"class_list":["post-4992","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-list","tag-list-operations","tag-python","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1iw","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4992","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=4992"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4992\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=4992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=4992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=4992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}