<kaggle_start><code>import numpy as np  # linear algebra
import pandas as pd  # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
import os

for dirname, _, filenames in os.walk("/kaggle/input"):
    for filename in filenames:
        print(os.path.join(dirname, filename))
# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All"
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session

# # Lists
# Lists in Python represent ordered sequences of values.
# -1 : It means to increment the index every time by -1, meaning it will traverse the list by going backwards.
#
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
planets[1]
# list[start:exlusive]
planets[2:5]
# list[start:stop:step]
planets[1:6:2]
# All the planets except the first and last
print(planets)
# The last 3 planets
planets[-3:]
# Reversing the list
planets[::-1]

# # Changing lists
# Lists are "mutable", meaning they can be modified "in place".
# One way to modify a list is to assign to an index or slice expression.
#
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
# planets[3] = 'Malacandra'
# print(planets)
planets[:3] = ["Mur", "Vee", "Ur"]
print(planets)

# # List functions
#
# How many planets are there?
len(planets)
# The planets sorted in alphabetical order
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
print(sorted(planets))
print(planets)
planets.sort()  # list.sort()
print(planets)
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
print(planets)
primes = [2, 3, 5, 7]
sum([1, 2, 3])
print(max(primes))
print(min(primes))

# # Interlude - Objects
# **Using the dot notation**
#
# x = 12
# # x is a real number, so its imaginary part is 0.
# print(x.imag)
# Here's how to make a complex number:
c = 12 + 3j
print(c.imag)

# # List methods
#
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
emptyList = []
print(planets)
planets.append("Corellia")
print(planets)
planets.pop()
print(planets)
planets.remove("Venus")
print(planets)
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
planets.index("Earth")
planets.index("fsdfsd")
"Venus" in planets
"fsdfsd" in planets

#
# Append()	Add an element to the end of the list
# Extend()	Add all elements of a list to the another list
# Insert()	Insert an item at the defined index
# Remove()	Removes an item from the list
# Pop()	    Removes and returns an element at the given index
# Clear()	    Removes all items from the list
# Index()	    Returns the index of the first matched item
# Count()	    Returns the count of number of items passed as an argument
# Sort()	    Sort items in a list in ascending order
# Reverse()	Reverse the order of items in the list
# copy()	    Returns a copy of the list
# [https://www.geeksforgeeks.org/python-list/#urm](http://)
# # Tuples
# Tuples are almost exactly the same as lists. They differ in just two ways.
# * The syntax for creating them uses parentheses instead of square brackets.
# * They cannot be modified (they are immutable).
tup = (1, 2, 3)
tup

# Activity - Write a Python program to Swap two variables
a = 1
b = 0
print(a, b)
a, b = b, a
print(a, b)

# # Slicing in tuples
# Slicing in tuples
a = (1, 2, 3, 4, 5)
sliceObj = slice(1, 3)
a[slice(1, 3)]


# # Practice questions
# Complete the function below according to its docstring.
def select_second(L):
    """Return the second element of the given list. If the list has no second
    element, return None.
    """
    pass


# Solution
def select_second(L):
    if len(L) < 2:
        return None
    return L[1]


# What are the lengths of the following lists? Fill in the variable lengths with your predictions. (Try to make a prediction for each list without just calling len() on it.)
a = [1, 2, 3]
b = [1, [2, 3]]
c = []
d = [1, 2, 3][1:]
# Put your predictions in the list below. Lengths should contain 4 numbers, the
# first being the length of a, the second being the length of b and so on.
lengths = []


# # Solution:
# #
# a: There are three items in this list. Nothing tricky yet.
# b: The list [2, 3] counts as a single item. It has one item before it. So we have 2 items in the list
# c: The empty list has 0 items
# d: The expression is the same as the list [2, 3], which has length 2.
# We're using lists to record people who attended our party and what order they arrived in. For example, the following list represents a party with 7 guests, in which Adela showed up first and Ford was the last to arrive:
# party_attendees = ['Adela', 'Fleda', 'Owen', 'May', 'Mona', 'Gilbert', 'Ford']
# A guest is considered 'fashionably late' if they arrived after at least half of the party's guests. However, they must not be the very last guest (that's taking it too far). In the above example, Mona and Gilbert are the only guests who were fashionably late.
# Complete the function below which takes a list of party attendees as well as a person, and tells us whether that person is fashionably late.
def fashionably_late(arrivals, name):
    """Given an ordered list of arrivals to the party and a name, return whether the guest with that
    name was fashionably late.
    """
    pass


def fashionably_late(arrivals, name):
    order = arrivals.index(name)
    return order >= len(arrivals) / 2 and order != len(arrivals) - 1
<|endoftext|>
[{"Id": 48202409, "ScriptId": 13002333, "ParentScriptVersionId": NaN, "ScriptLanguageId": 9, "AuthorUserId": 6204353, "CreationDate": "11/30/2020 15:56:58", "VersionNumber": 2.0, "Title": "notebook05985af1f6", "EvaluationDate": "11/30/2020", "IsChange": false, "TotalLines": 238.0, "LinesInsertedFromPrevious": 0.0, "LinesChangedFromPrevious": 0.0, "LinesUnchangedFromPrevious": 238.0, "LinesInsertedFromFork": NaN, "LinesDeletedFromFork": NaN, "LinesChangedFromFork": NaN, "LinesUnchangedFromFork": NaN, "TotalVotes": 0}]
import numpy as np  # linear algebra
import pandas as pd  # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
import os

for dirname, _, filenames in os.walk("/kaggle/input"):
    for filename in filenames:
        print(os.path.join(dirname, filename))
# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All"
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session

# # Lists
# Lists in Python represent ordered sequences of values.
# -1 : It means to increment the index every time by -1, meaning it will traverse the list by going backwards.
#
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
planets[1]
# list[start:exlusive]
planets[2:5]
# list[start:stop:step]
planets[1:6:2]
# All the planets except the first and last
print(planets)
# The last 3 planets
planets[-3:]
# Reversing the list
planets[::-1]

# # Changing lists
# Lists are "mutable", meaning they can be modified "in place".
# One way to modify a list is to assign to an index or slice expression.
#
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
# planets[3] = 'Malacandra'
# print(planets)
planets[:3] = ["Mur", "Vee", "Ur"]
print(planets)

# # List functions
#
# How many planets are there?
len(planets)
# The planets sorted in alphabetical order
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
print(sorted(planets))
print(planets)
planets.sort()  # list.sort()
print(planets)
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
print(planets)
primes = [2, 3, 5, 7]
sum([1, 2, 3])
print(max(primes))
print(min(primes))

# # Interlude - Objects
# **Using the dot notation**
#
# x = 12
# # x is a real number, so its imaginary part is 0.
# print(x.imag)
# Here's how to make a complex number:
c = 12 + 3j
print(c.imag)

# # List methods
#
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
emptyList = []
print(planets)
planets.append("Corellia")
print(planets)
planets.pop()
print(planets)
planets.remove("Venus")
print(planets)
planets = [
    "Mercury",
    "Venus",
    "Earth",
    "Mars",
    "Jupiter",
    "Saturn",
    "Uranus",
    "Neptune",
]
planets.index("Earth")
planets.index("fsdfsd")
"Venus" in planets
"fsdfsd" in planets

#
# Append()	Add an element to the end of the list
# Extend()	Add all elements of a list to the another list
# Insert()	Insert an item at the defined index
# Remove()	Removes an item from the list
# Pop()	    Removes and returns an element at the given index
# Clear()	    Removes all items from the list
# Index()	    Returns the index of the first matched item
# Count()	    Returns the count of number of items passed as an argument
# Sort()	    Sort items in a list in ascending order
# Reverse()	Reverse the order of items in the list
# copy()	    Returns a copy of the list
# [https://www.geeksforgeeks.org/python-list/#urm](http://)
# # Tuples
# Tuples are almost exactly the same as lists. They differ in just two ways.
# * The syntax for creating them uses parentheses instead of square brackets.
# * They cannot be modified (they are immutable).
tup = (1, 2, 3)
tup

# Activity - Write a Python program to Swap two variables
a = 1
b = 0
print(a, b)
a, b = b, a
print(a, b)

# # Slicing in tuples
# Slicing in tuples
a = (1, 2, 3, 4, 5)
sliceObj = slice(1, 3)
a[slice(1, 3)]


# # Practice questions
# Complete the function below according to its docstring.
def select_second(L):
    """Return the second element of the given list. If the list has no second
    element, return None.
    """
    pass


# Solution
def select_second(L):
    if len(L) < 2:
        return None
    return L[1]


# What are the lengths of the following lists? Fill in the variable lengths with your predictions. (Try to make a prediction for each list without just calling len() on it.)
a = [1, 2, 3]
b = [1, [2, 3]]
c = []
d = [1, 2, 3][1:]
# Put your predictions in the list below. Lengths should contain 4 numbers, the
# first being the length of a, the second being the length of b and so on.
lengths = []


# # Solution:
# #
# a: There are three items in this list. Nothing tricky yet.
# b: The list [2, 3] counts as a single item. It has one item before it. So we have 2 items in the list
# c: The empty list has 0 items
# d: The expression is the same as the list [2, 3], which has length 2.
# We're using lists to record people who attended our party and what order they arrived in. For example, the following list represents a party with 7 guests, in which Adela showed up first and Ford was the last to arrive:
# party_attendees = ['Adela', 'Fleda', 'Owen', 'May', 'Mona', 'Gilbert', 'Ford']
# A guest is considered 'fashionably late' if they arrived after at least half of the party's guests. However, they must not be the very last guest (that's taking it too far). In the above example, Mona and Gilbert are the only guests who were fashionably late.
# Complete the function below which takes a list of party attendees as well as a person, and tells us whether that person is fashionably late.
def fashionably_late(arrivals, name):
    """Given an ordered list of arrivals to the party and a name, return whether the guest with that
    name was fashionably late.
    """
    pass


def fashionably_late(arrivals, name):
    order = arrivals.index(name)
    return order >= len(arrivals) / 2 and order != len(arrivals) - 1
