<jupyter_start><jupyter_text><jupyter_code>nums = list(range(5))     # range is a built-in function that creates a list of integers
print(nums)               # Prints "[0, 1, 2, 3, 4]"
print(nums[2:4])          # Get a slice from index 2 to 4 (exclusive); prints "[2, 3]"
print(nums[2:])           # Get a slice from index 2 to the end; prints "[2, 3, 4]"
print(nums[:2])           # Get a slice from the start to index 2 (exclusive); prints "[0, 1]"
print(nums[:])            # Get a slice of the whole list; prints "[0, 1, 2, 3, 4]"
print(nums[:-1])          # Slice indices can be negative; prints "[0, 1, 2, 3]"
nums[2:4] = [8, 9]        # Assign a new sublist to a slice
print(nums)               # Prints "[0, 1, 8, 9, 4]"
fruits = ['apple', 'mango', 'banana', 'orange', 'grapes']
print(fruits)
fruits[1], fruits[-4] # to start counting from end start with -1
fruits[4], fruits[-1]
fruits[4][1] # to print r in grapes in fruits list
fruits[1 : 3] # print slice from 1 poition till 3rd position not including 3rd poition content
fruits[0 : 3]
fruits[0 : -1] # slicing till the last one, not including the last one
fruits[1 : -1]
fruits[0::2] # jump using two ::
# we are jumping two places
fruits[0::4]
fruits[::-1] # invert the list
mixed_list = [1, 'one', 2, 'two', 3, 'three', 4.5, 'four point five', True] 
# combining strings and int and floats and booleans
mixed_list
len(mixed_list) # to return the length of contents in list
# a list can take mixed data types
type(mixed_list) # type with return type
type(mixed_list[2]), type(mixed_list[1]), type(mixed_list[6]), type(mixed_list[8])
len(mixed_list[7]), len(mixed_list[5]) # len will return the lenth of string here
len(mixed_list[6])
len(mixed_list[0])
len(mixed_list[8])
# object of type 'int', 'float', 'bool' has no len()
fruits = ['apple', 'mango', 'banana', 'orange', 'grapes']
vegetables = ['carrots', 'brocolli', 'spinach', 'cucumber']
# I want to combine fruits and vegetables in a list groceries
groceries = fruits + vegetables
groceries
groceries[5]
fruits, vegetables
# let's see the function for list called append
fruits.append(vegetables)
fruits 
fruits[5]
vegetables
# confused? go down
planets_t = [] # making an empty list 't = terrestrial'
planets_t
planets_t.append('mercury') # mercury is going to be added to the list 
planets_t
planets_t.append('venus') # adding venus to list planets in the end
planets_t
planets_t.append('earth')
planets_t
planets_t.append('mars')
planets_t
planets_g = [] # 'g = gas giants'
planets_g.append('jupyter')
planets_g
planets_g.append('saturn')
planets_g
planets_i = [] # 'i = ice giants'
planets_i.append('uranus')
planets_i
planets_i.append('neptune')
planets_i
print(planets_t)
print(planets_g)
print(planets_i)
solar_system = planets_t + planets_g + planets_i
solar_system
planets_t_1 = planets_t # putting the contents of planets_t into planets_t_!
planets_t_1
planets_t_1.append(planets_g)
planets_t_1.append(planets_i)
planets_t_1
planets_t # even planets_t is being affected 
# because both lists are same
# i.e. they are occupying the same memory space in the computer, 
# their address is same
 # append is only taking one thing at a time, one string, one number or one list!
planets_g_1 = planets_g
planets_g_1
planets_g_1.extend(planets_i)
planets_g_1 
# extend will properly add contents to the original list, not the whole list as in append function
# extend can take multiple contents at a time
planets_g # also planet_g is being affected
# to combine multiple list best function to use is extend
# to add a content to the list append is better
planets_g == planets_g_1 # boolean condition to check their equality
p_list = ['jupyter', 'saturn', 'uranus', 'neptune'] # making a new list
p_list == planets_g # comparing old list with same contents with new list
# it's true because their content is same
p_list.pop() # pop function removes the last content from the list
p_list.pop()
p_list
p_list.remove('jupyter') # removes the exact content that we want from the list
p_list # now our list only has saturn :p
# let's try to remove more than one content from solar_system
solar_system
solar_system.remove('mercury', 'jupyter', 'uranus')
solar_system.remove(['mercury', 'jupyter', 'uranus'])
# so we can only remove one thing at a time from list using remove
solar_system.reverse() # reverse function will reverse everything in the list
solar_system
solar_system.index('saturn'), solar_system.index('earth')
# index function returns the index location of our content
solar_system.insert(0, 'pluto')
# inserting pluto in 0 index position
solar_system
solar_system.insert(5, 'ceres')
# insert ceres in index position 5
solar_system
solar_system.sort()
# to sort our list in ascending oe=rder
solar_system
# sorted list in ascending alphabetical order
solar_system.sort(reverse = True)
# to sort in descending order give reverse = True as an argument to sort()
solar_system
solar_system_1 = solar_system.copy()
# to copy the content from one list to other list but in a different memory in computer
solar_system_1.append(fruits)
solar_system_1
solar_system
solar_system_2 = solar_system.copy()
solar_system == solar_system_2 # check whether they are same
solar_system is solar_system_2 # they do not refer to the same object
solar_system[0] = 'sun'
# replacing venus with sun at first position
# instead of removing and inserting, directly replace the content
solar_system
solar_system_3 = ['mercury', 'venus', 'earth', 'mars', 'jupyter', 'saturn', 'uranus', 'neptune']
'sun' in solar_system_3
'earth' in solar_system_3 # to check whether the content is in the list or not
solar_system_3['earth' in solar_system_3] # becasue ''earth' in solar_system_3' is True which is 1, and
# solar_system[1] is venus
solar_system_3['sun' in solar_system_3] # becasue ''sun' in solar_system_3' is False which is 0, and
# solar_system[1] is mercury
fruits = ['apple', 'mango', 'banana', 'orange', 'grapes']
other_fruits = fruits                 # Point other_fruits at what fruits is pointing to
print(other_fruits is fruits)         # => True, fruits and other_fruits refer to the same object
print(other_fruits == fruits)         # => True, fruits's and other_fruits's objects are equal

other_fruits = ['apple', 'mango', 'banana', 'orange', 'grapes']  # Point other_fruits at a new list, ['apple', 'mango', 'banana', 'orange', 'grapes']
print(other_fruits is fruits)             # => False, fruits and other_fruits do not refer to the same object
print(other_fruits == fruits)            # => True, fruits's and other_fruits's objects are equal
# we saw few functions: 
# append
# extend
# insert
# remove
# pop
# reverse
# index
# sort
# Loops
for value in [1, 2, 3, 4]:  # the keyword value we defined will look in the list,
  # will pick the values from list
  print(value) # and print it one by one untill all values are printed
for i in [1, 2, 3, 4]:
  print(i) # the iteration continues till last value is printed
for i in solar_system_3:
  print(i)
print(' The planet name is: ', solar_system_3[0])
for i in solar_system_3:
  print(' The planet name is: ', i)
for i in solar_system_3[0:4]: # printing top 4 only
  print(i)
for i in solar_system_3[0::2]: # jump to second position
  print(i)
# I want to print earth and uranus, index position 2 and 6
for i in solar_system_3[2::4]:
  print(i)
for i in solar_system_3:
    print(i[0])
for i in solar_system_3[0]:
    print(i)
for i in solar_system_3:
    print("the planet is ", i)
for i, j in enumerate(solar_system_3):
    print("the" , i + 1, " planet is ", j)
# Function
mon =[]  # make empty lists to store the values of our return
dat = []
ye = []

def dob():   # a function which asks for the dob and prints out in  a proper format
    m = input("Month you were born: ")
    d = input("Date you were born: ")
    y = input("Year you were born: ")
    
    print('mm/dd/yyyy: ', m, '/', d, '/', y)
    
    return m, d, y
for i in range(3):
    month, date, year = dob()
    mon.append(month)
    dat.append(date)
    ye.append(year)
print(mon)
print(dat)
print(ye)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1083994053518335, 'fraction_numerical': 0.017963330029732407, 'mean_word_length': 4.462110960757781, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '612132', 'license': 'MIT', 'n_tokens_mistral': 2842, 'n_tokens_neox': 2736, 'n_words': 1035, 'path': 'Python/Lists.ipynb', 'repo_name': 'Nik8x/Code_comparison', 'size': '8072'}