really-simple-ssl
domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home3/c2planpf/public_html/wp-includes/functions.php on line 6114wordpress-seo
domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home3/c2planpf/public_html/wp-includes/functions.php on line 6114Lists are one of the important python data structure widely used for solving numerical, statistical problems. Lists are more like arrays in other programming languages, But lists are a heterogeneous data structure, List is defined with items separated by the comma (\u201c,\u201d ) and enclosed by square brackets (\u2018[]\u2018)<\/p>\n
This below example using Jupyter notebook shows creating python list. In Jupyter notebook, the output of each line is given immediately after the line.<\/p>\n
Creating List in Python:<\/strong><\/p>\n In the given example we are creating list_ex <\/em><\/strong>which is a list of numbers, other list list2<\/em> <\/strong>which is a list of alphabets, the other list list_hetro<\/em><\/strong> is a heterogeneous list which contains numbers, alphabets, and strings as list items. Python len() <\/strong>function is used to get the length of the list which indicates no of elements present in the list.<\/p>\n <\/p>\n <\/p>\n Accessing elements of lists and update List values in Python:<\/strong><\/p>\n List elements in the python lists can be accessed using the index. List index starts from zero and the index of the final element of the list is N-1 (N = length of the list).<\/p>\n list_ex[0] gives the first element of the list.<\/p>\n list_hetro[3] gives the 4th<\/sup> element of the list which is \u201cconcept\u201d.<\/em><\/strong><\/p>\n Similarly to update the values in this list we can use indexing for updating.<\/p>\n list_hetro[3] = “c2plabs.com” <\/strong>This statement updates 4th<\/sup> element of list to \u201cc2plabs.com\u201d. <\/strong>Updated list can be seen by printing the list.<\/p>\n Deleting list element:<\/strong><\/p>\n List elements can be deleted using the index, an example to delete 5th<\/sup> Element list_hetro <\/strong><\/p>\n del list_hetro[5] <\/strong># This statement deletes element \u201cprototype\u201d from the list.<\/p>\n <\/p>\n Slice Operator [:] and Slicing of List in Python:<\/strong><\/p>\n Slice Operator [:] is used to extract a single element or ranges of elements from the list.<\/p>\n The syntax of slice operator is list_name [start_index : end_index]<\/strong><\/p>\n Ex: new_list=list_hetro [1:3] <\/strong>#In this statement start index is 1 and end index is 3, in slicing operation end index is excluded.<\/p>\n Above statement create new list form list_hetro element from index \u201c1\u201d to index \u201c2\u201d excluding end index which is 3 here.<\/p>\n To get the final or last element of the list end index is \u201c-1\u201d. <\/strong>Given example shows how to use slice operator to access list items.<\/p>\n <\/p>\n Python Built-in functions:<\/strong><\/p>\n Python offers built-in functions to work on lists.<\/p>\n Len (list) : <\/strong>Length of the list, No of elements present in the list.<\/p>\n Max(list) : <\/strong>This function returns maximum value present in the list.<\/p>\n Min(list) : <\/strong>This function return minimum value present in the list.<\/p>\n <\/p>\n List methods:<\/strong><\/p>\n Python lists have methods to perform different operations on the list like<\/p>\n list.append (object) :<\/strong> This method appends new object to list<\/p>\n list.count (object):<\/strong> This method returns the count of occurrence of the object in the given list<\/p>\n list.remove(object):<\/strong> This method removes the first occurrence of the object from the list<\/p>\n list.insert (index, object):<\/strong> This method inserts the object at a index specified.<\/p>\n In the below given example we are defining list_new as<\/p>\n list_new = [“c2plabs.com”, “concept”, 2, “prototype”]<\/p>\n New elements “Machine”, “Learning”, “c2plabs.com” are added to list using append method.<\/p>\n This example also shows counting no of occurrences of “c2plabs.com” using list.count() method.<\/p>\n <\/p>\n This example also shows the usage of list methods like list.remove() and list.insert.<\/p>\n","protected":false},"excerpt":{"rendered":" Lists are one of the important python data structure widely used for solving numerical, statistical problems. Lists are more like arrays in other programming languages, But lists are a heterogeneous data structure, List is defined with items separated by the comma (\u201c,\u201d ) and enclosed by square brackets (\u2018[]\u2018) This below example using Jupyter notebook shows […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[85],"tags":[74,73],"class_list":["post-382","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-basics","tag-python-lists"],"yoast_head":"\n