<jupyter_start><jupyter_text>Python Collections (Arrays)There are four collection data types in the Python programming language:   List is a collection which is ordered and changeable. Allows duplicate members.   Tuple is a collection which is ordered and unchangeable. Allows duplicate members.   Set is a collection which is unordered and unindexed. No duplicate members.   Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.When choosing a collection type, it is useful to understand the properties of that type. Choosing the right type for a particular data set could mean retention of meaning, and, it could mean an increase in efficiency or security.  ListA list is a collection which is ordered and changeable. In Python lists are written with square brackets.<jupyter_code>list = ["apple", "banana", "cherry"]
print(list)<jupyter_output>['apple', 'banana', 'cherry']<jupyter_text>List MethodsPython has a set of built-in methods that you can use on lists.|           Methods              |                        Description                                         ||append()                        |Adds an element at the end of the list                                      ||clear()                         |Removes all the elements from the list                                      ||copy()                          |Returns a copy of the list                                                  ||count()                         |Returns the number of elements with the specified value                     ||extend()                        |Add the elements of a list (or any iterable), to the end of the current list||index()                         |Returns the index of the first element with the specified value             ||insert()                        |Adds an element at the specified position                                   ||pop()                           |Removes the element at the specified position                               ||remove()                        |Removes the item with the specified value                                   ||reverse()                       |Reverses the order of the list                                              ||sort()                          |Sorts the list                                                              |<jupyter_code># Access Items:You access the list items by referring to the index number:
# Example Print the second item of the list:

thislist = ["apple", "banana", "cherry"]
print(thislist[2])
#Change Item Value:To change the value of a specific item, refer to the index number:
#Example: Change the second item:

thislist = ["apple", "banana", "cherry"]
thislist[1] = "blackcurrant"
print(thislist)
# Loop Through a List:You can loop through the list items by using a for loop:

# Example: Print all items in the list, one by one:

thislist = ["apple", "banana", "cherry"]
for x in thislist:
  print(x)
# Check if Item Exists:To determine if a specified item is present in a list use the in keyword:

# Example: Check if "apple" is present in the list:

thislist = ["apple", "banana", "cherry"]
if "apple" in thislist:
  print("Yes, 'apple' is in the fruits list")
#List Length:To determine how many items a list have, use the len() method:

#Example: Print the number of items in the list:

thislist = ["apple", "banana", "cherry"]
#a=len(thislist)
print("Length of all thelist is:", +len(thislist))
# Add Items:To add an item to the end of the list, use the append() method:

# Using the append() method to append an item:

thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
# To add an item at the specified index, use the insert() method:

# Example:Insert an item as the second position:

thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
print(thislist)
#Remove Item:There are several methods to remove items from a list:

# Example: The remove() method removes the specified item:

thislist = ["apple", "banana", "cherry"]
thislist.remove("banana")
print(thislist)
# Example:The pop() method removes the specified index, (or the last item if index is not specified):

thislist = ["apple", "banana", "cherry"]
thislist.pop(1)
print(thislist)
# Example: The del keyword removes the specified index:

thislist = ["apple", "banana", "cherry"]
del thislist[0]
print(thislist)

# Example:The del keyword can also delete the list completely:

thislist = ["apple", "banana", "cherry"]
del thislist
print(thislist) 
#this will cause an error because "thislist" no longer exists.
# Example: The clear() method empties the list:

thislist = ["apple", "banana", "cherry"]
thislist.clear()
print(thislist)
# The list() Constructor: It is also possible to use the list() constructor to make a list.

# Example: Using the list() constructor to make a List:
thislist = ["apple", "banana", "cherry"]
a=list(("apple", "banana", "cherry")) # note the double round-brackets
print(a)
print(thislist+a)<jupyter_output>['apple', 'banana', 'cherry']
['apple', 'banana', 'cherry', 'apple', 'banana', 'cherry']
{'fraction_non_alphanumeric': 0.09504132231404959, 'fraction_numerical': 0.0009838646202282567, 'mean_word_length': 2.6385110952040085, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '321719', 'license': 'MIT', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1275, 'n_words': 601, 'path': 'List .ipynb', 'repo_name': 'AswithaKorlagunta/pythonpractise', 'size': '5082'}