Galvanize DSI Prep

Ace your homework & exams now with Quizwiz!

What are all the whitespaces in Python? How can you filter the using a for loop?

' ' - Space '\t' - Horizontal tab '\n' - Newline '\v' - Vertical tab '\f' - Feed '\r' - Carriage return

How do you use the math module? What is its syntax?

"import math" imports the math module. Then to use the math functions use the syntax math.function_name(object).

How are DeMorgan's laws interpreted?

1. DeMorgan's first law states that the complement of the union of two sets is the same as the intersection of their complements. 2. DeMorgan's second law states that the complement of the intersection of two sets is the same as the union of their complements.

What are some attributes of the sorted() function?

1. Function sorts lists or strings of the same data type e.i. numeric or alphabet. It does not sort strings or lists with mixed data. 2. Capitalized words or letters have precedence over lower case. This due to having lower numeric values in memory storage. 3. Function can use optional arguments. For example, if you want to sort a list in descending order, you can specify reverse = True.

What are some important rules to keep in mind when using default arguments?

1. If you are just using one default argument place it at the end when defining the function parameters. 2. If you name all your arguments during function call you can rearrange the arguments and parameters as you please. Otherwise you would get an argument placement error. 3. There's really no need to switch around your arguments during function call so avoid rearranging arguments unless absolutely necessary.

How should a boolean flag code be structured?

1. Initialize the flag to some known Boolean value, BEFORE the loop 2. INSIDE the loop, tests for the condition that should set the flag and sets the flag to the opposite Boolean value if the condition holds 3. AFTER the loop, tests the flag to see if the condition held sometime during the execution of the loop

What are some important rules to remember when slicing a list?

1. The list can be sliced backwards by negative numbers. 2. The last index is never inclusive even if you slice the index backwards with a negative number. This means that you have to intentionally create the list 1 element higher to access the last element. 3. When creating sublists, any new updates/changes made to the original list do not affect the sublist and vise-versa

What is a factorial?

A factorial is the product of an integer and all the integers below it; e.g. factorial four ( 4! ) is equal to 24.

Since lists are mutable this means that the objects within can be modified. What are some builtin functions that can be used to modify a list?

A list can be modified with the .append, del, .pop, zip() class method and more. The = operator can also be used to change an element in the list by calling its index and assigning a new element. list[index] = new_element.

What is a list in Python? In what ways can it be expressed?

A list is a mutable data structure that has its elements sequentially indexed. A list is defined using a set of square brackets [] and the elements and items that go inside of it could be of any type.

What is the formula of the mean or average in probability and/or statistics?

A mean is derived by calculating the sum of all the values in a collection, then dividing that sum by the total number of items.

Since search for key that does not exist in a dictionary returns an error, what is safe practice commonly used?

A safe practice is to create a conditional statement that returns a string that notifies the user that the key is not in the dictionary.

What is a scalar type?

A scalar type holds a single value, like "1", "3.1415", or "Elf".

What is the identity property in set algebra?

A set has the indentity property under a particular operation if there is an element of that set that leaves every other element of the set unchanged under a given operation.

What is a set in mathematics?

A set in mathematics is simply a collection of well defined and distinct objects, and is also an object in its own right.

What does instantiating an object mean and how does it relate to a class method.

An object, such as a list, needs to be instantiated in order to use the methods associated with that object. Instantiation simply means "to create an instance of", or declare. For example, instantiating a list object can look like this: some_list = [1,2,3,4].

What does flattening mean in Python?

Flattening lists means converting a multidimensional or nested list into a one-dimensional list.

What do f-strings do and how do they differ from the str.format() method?

Like the format() method, f-strings are a way to format strings. The advantage of f-strings is that they are easily readable and more compact than the str.format() method. The main disadvantage is that it isn't as versatile.

How may using multiple variables on a line graph come handy?

Line graphs can be used to display multiple variables, often so a comparison can be made. This most important when the demand to compare and contrast the performance and of trends of multiple locations.

Tuples can also be concatenated and unpacked.

Note: When multiple items are returned in a function they are returned as a tuple

What are the commonly used notations for the mode?

Similar to median, there is no consensus on the notations used to describe mode but Mo (capital m and lowercase o)

Why is it a common practice to spread a dictionary into multiple lines?

Spreading a dictionary over multiple lines helps with readability.

What are the 3 fundamental properties of set algebra?

The 3 fundamental properties of set algebra are Commutative Associative and Distributive.

what does the character '\n' do in Python?

This character makes a new line between what is before and what comes after.

How do arithmetic operators work on boolean objects?

True and False objects are also 0 and 1 values so so the arithmetic will be done on the 0 and 1 values.

Tuples are very similar to lists and strings. What are some properties that tuples share in common with lists and strings?

Tuples can be accessed using indexing and slicing, they can use the len method, and they can check/search for an object just like a list and a string.

What are the three ways of declaring a tuple?

Tuples can be declared by using parenthesis, using the tuple constructor, and using comma separated values. remember that the constructor will only take an iterable object as its argument and that tuples with only 1 element need a comma right afterwards.

What does the random function from the random module or random.random() do?

Use the random function from the random module when you need to generate a random float in the interval [0.0, 1.0). This function will be useful when you are trying to generate probabilities. Note that the interval is semi-open, meaning 1.0 is not a possible outcome.

What do *args do what type of object do they return?

Using *args as a parameter allows you the user to pass in an arbitrary number of unnamed arguments to the function. When you use this in a function definition, it must come after all other parameters and when you use it, all of the arguments passed in will be wrapped up in a tuple.

Why is using a counter in a while important?

Using a counter in a while is important because it acts as a break or exit for the while loop and allows the programmer to specify how many iterations they would like the while loop to go through. Once they know the while loop exits without creating an infinite loop then they can remove the extra exit statement.

What is the parity of an integer in Python and how do you check the parity of a number?

When someone asks what is the parity of an integer, they are asking if it is even or odd. A number is even if it is perfectly divisible by 2. When the number is divided by 2, we use the remainder modulo operator % to compute the remainder. If the remainder is not zero, the number is odd.

What are some of the whitespace operators? And how do you check for them?

Whitespace characters include newlines ("\n"), tabs ("\t"), spaces, and carriage returns ("\r"). To check if a string is all whitespace, you can use the str.isspace() method.

Like strings, Python also uses zero indexing for lists. How do you access or call the elements of a list?

You access a lists index by using the square brackets [] after the list. list[index]. You can also use negative index to call the list backwards from the end. list[-index]. Note that the when accessing the list with a : the last index is non inclusive so you have to add an additional index to get the last digit

What is an algorithm?

an algorithm is a set of instructions necessary to perform a well-defined task.

How are the keywords in and not used to search for elements in a list?

by following the format element in list or element not in list you get a boolean whether the element is in the list. You can also assign these statements to a variable for convenience. variable = element in list or variable = element not in list.

How are scatter plots with additional values displayed?

by using shapes, color, and size we can represent additional variables on a scatter plot. While the variables on the x and y axes must be numerical, the additional variables do not share the same restriction.

What is an compiled Language?

compiled languages are "translated" into a target language (like assembly or machine code) before running. If any errors exist in your program, the compiler will fail and your code won't be able to run until all of the errors are fixed.

What is control flow in Python?

control flow is the aspect of programming which allows our code to "make decisions" and execute code dynamically based on conditions. A Python program is regulated by conditional statements, loops, and function calls.

How do you replace an index in a string using the .join class method?

create a function that takes in the string which needs to be modified, the index, and the new character. Convert the string into a list the set the index of the list to the new character. Finally turn the list back into a string by using the .join method.

What are dictionaries in Python?

dictionaries are data structures composed of key/value pairs. The key must be an immutable type (int, float, string, tuple, etc) and an unique object that only has one occurrence of a given key. The value can be any type in Python, including objects defined by the user.

How do you declare a list?

empty list, some_list = [] or some_list = list() lists with values, some_list = [3, 2, 9, 18, 34] repeated values, some_list = [7] * 10 repeated sequence of values , some_list = [1, 3] * 5

How do you get the divisors of a natural number in Python?

first create a function that takes in one argument. Next create an accumulator for the divisors of the numbers passed through the function. iterate through a range of 1 to your argument. In the body create a conditional if statement of your argument % iterable range equal to 0. Finally append those iterables to your accumulator. *Note that this problem can be solved in multiple different ways.

How do you unpack a nested list into a single list or accumulator?

first create an empty list or accumulator. Then run the nested list through a nested for loop. Finally append the each element into the empty list and print the empty NEW list outside of the for loop.

What do the if, elif, and else statements do?

if, elif, and else are conditional statements or conditional constructs that are used to perform different computations or actions depending on whether a condition evaluates to True or False.

What's the difference between an int and an integer?

int refers to the Python data type, and integer refers to the mathematical object.

What is a integer type in Python?

integer, is a whole number, positive or negative, without decimals, of unlimited length. *Note: dividing integers in Python returns a float.

What do the functions max() and min() do? What are some important attributes of the min() and max() functions?

max() finds the maximum value in a list and min() finds the minimum value in a list. Some things to remember. 1. Using the .remove method with the max and min function only removes the first instance. 2. Function works on lists or strings of the same data type e.i. numeric or alphabet. It does not work on strings or lists with mixed data.

What is the difference between a parameter and an argument?

parameters are variables defined in a function definition and arguments are the values/variables that get passed to the function.

How does the .extend() method deal with str types (strings?

when you extend a list with a str type object, it splits the string into individual characters, and then adds each of those characters to the list individually.

What do **kwargs do? how are they different than *args?

**kwargs is a dictionary that allows you to pass in named arguments. They can be unpacked like a dictionary within the function.

What are *args and **kwargs?

*args and *kwargs are ways to pass in an arbitraily long list of values.

What is bar graph and what are the two types of bar graph?

A bar plot is a visualization which can be used to show comparisons among discrete categories. The stacked bar chart is useful for looking at an aggregate value, as well as the individual parts which make up an aggregation. The other bar plot is a grouped bar plot. Much like the stacked bar plot, we can express more information in the plot by grouping bars together. * the example contains a combination of grouped/stacked bar.

What is a box and whisker plot and what does it represent?

A box and whisker plot is also commonly referred to as a box plot. The box plot is a visual representation of the five number summary. Much like a histogram, a box plot can show the general characteristics of a distribution. The box portion of the box and whisker plot visualizes the values which lie in the middle two quartiles; box plots also have vertical lines extending from the box to show the upper and lower quartile, these are referred to as the "whiskers" of the plot. The spacings between the different parts of the box and whisker plot give a rough indication of how a distribution is spread

What is a calling object? How does it relate to a class method?

A calling object is the object on which a class method is called upon. For example if we append an item to list lst. lst.append(item). lst is the calling object, .append is the class method, and item is the object being appended to the list (inside parenthesis).

What is a character in Python?

A character is a single unit of information like a letter, number, symbol or space, and is always 1 length long. Characters are essentially the building blocks of strings.

What is the definition of statistics?

A collection of mathematics used to summarize, analyze, and interpret a group of numbers or observations.

What are combinations and how are they and same or different from permutations?

A combination is much like a permutation, though when dealing with combinations, order doesn't matter. Specifically, in a lottery with sixty possible balls to choose from (numbered from 1-60), where six balls are chosen at random, the combination {3,6,8,4,7} is considered the "same outcome" as {7,4,3,6,8} because the balls chosen are the same and order doesn't matter.

What is the common function used to calculate the number of bins of a histogram?

A common function to calculate the number of bins is k equals square root of n. Where k represents the number of bins, and n represents the number of samples in a data set.

What's a common plotting technique often seen on a scatter plot?

A common plotting technique often seen on a scatter plot is a "best-fit" line. A best-fit line shows the "average" relationship between two variables and can be used to make approximations or predictions of unknown values. When the fitted line has a negative slope, the variables have a negative correlation. When the fitted line has a positive slope, there is a positive correlation.

What is a conditional check in Python?

A conditional check is a while loop that has a an initialization variable before the loop that acts as a form of exit point. In the example above is the x variable set to 20. If the statement is properly set then the while loop will stop once the counter in the body meet the condition. This prevents the while loop from becoming an infinite loop.

What is a default argument and when is it useful?

A default argument is a argument that is assigned to a functions parameter when the function is being defined. This is normally done when the argument that will be passed into a certain parameter will rarely change. If a default value is set, then the user is not required to pass an argument into that function for that parameter.

What does a for loop do?

A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). ... With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.

What is a function? What is most common usage?

A function is a block of code which only runs when it is called. When defining the function, the names used to represent passed in data are referred to as parameters. When actually using, or calling the function, the data passed in are referred to as arguments. The most common use of a function is to make procedures automated and repeatable.

What are some properties to remember about the return keyword in a function?

A function returns a tuple if returning objects are more than one. If you are only returning one object then that object type will be returned. You can assign values

although the exact format that docstrings take will vary to some degree based on the company that you work for, what is a good starting point?

A good starting point is the format that the NumPy package uses which is broken up into 3 parts. The Description, Parameters, Return with the Pass keyword at the end of the docstring.

What are histograms?

A histogram is a chart which shows frequencies for intervals of continuous numeric values. These intervals are often referred to as "buckets" or a "bin". The y-axis of a histogram always represents the frequency, while the x-axis represents the values to be represented. The histogram is an effective way of visualizing how a numerical attribute of a dataset is distributed, in other words it can be interpreted as an estimate of the probability distribution of a continuous variable.

What is a library and how is different or similar to a module?

A library is essentially a collection of modules. For example, the Python Standard Library is a library of all the modules that are distributed with a Python installation. Some other important libraries are matplotlib, pandas, and numpy. The key difference is that a module is a single Python file with a .py extension. A library is a term for a grouping of modules that share a common name.

What is Bayes' Theorem?

Bayes' theorem describes the probability of a posterior event, based on previous conditions related to the event. For example, given the probabilities P(B) and P(BIA), Bayes' theorem can be applied to calculate P(AıB).

What is a line chat/graph?

A line graph is a chart which represents two variables in cartesian coordinates. The chart is constructed by a series of data points called "markers," which are connected by straight line segments. This is one of the most common plots which you will encounter in data visualization, and it is imperative to have a fluency in the creation and interpretation of line graphs.

What is the difference between a function and a method?

A method, like a function, is a set of instructions that perform a task. The difference is that a method is associated with an object, while a function is not.

What is a python module and how are they accessed?

A module is a Python file that defines one or more variable(s), function(s), and/or class(es) that can then be reused in other scripts. The import key will run all of the code in the module's file.

What is a mutable object in Python and what if two lists contain the same values?

A mutable object is an object which itself or its content can be changed and modified without affecting the id(). if multiple list types contain the same values their id will be different.

What is a variable? What operator is used to assign a variable?

A name you use to reference values stored in memory so that you can reuse them. You can assign any data type to a variable. You can also declare multiple values at the same time. The operator used to assign a a variable is '='.

What is a pie chart and how does it compare to a bar chart?

A pie chart is a circular statistical chart, divided into slices to portray proportions of a population. There are a number of different variations of pie charts, but this lesson will stick to the basics. While pie charts are quite common, there is some consensus amongst those who specialize in data visualization that they can be an ineffective way of expressing data. The primary reason is that it can be difficult to compare the size of slices which are similar; an argument is also made that comparing one pie chart to another can be very difficult. For these reasons, a bar chart is often a good alternative to visualize proportions. Despite these challenges, pie charts do still maintain some utility due to the fact that they are familiar and easily interpreted by non-technical individuals.

What is a random experiment?

A random experiment is an experiment or a process for which the outcome cannot be predicted with certainty.

What are the properties of the and operator?

A statement using and will need both operands to be booleans to properly work. and statements evaluate True only if both operands are true.

What are the properties of an or statement?

A statement using or will return True if either part of the statement is true.

What is a string?

A string is a collection of characters. In simple terms, words, sentences, and paragraphs would all be interpreted in Python as a string. However, numbers can also be represented as strings, such as '123'. Such a string cannot be manipulated mathematically without converting it to an int or float first

What is a tuple?

A tuple is an ordered, immutable collection of items that is very similar to a list but with fewer associated methods due to its immutable property. A tuple is declare by using parenthesis at at the start and end of the tuple.

What is the difference between a variable in the local vs global scope?

A variable in a local scope is defined with in the function in question. A variable in a global scope is define outside of the function.

What is an important distinction about permutations?

A very important distinction with permutations is that permutations counts each possible way a set is chosen where order matters, that is choosing the elements {3,6,8,4,7} is not considered the same as {7,4,3,6,8}, even though the elements are the same.

What is Test Driven Development (TDD)?

A very popular programming paradigm where software engineers/developers write tests (code that tests the function of other code) prior to writing the code that will solve the actual problem. This forces the programmer to think about how the new function will be used prior to it's writing.

What is a float (floating point real values) in Python?

Also called floats, they represent real numbers and are written with a decimal point dividing the integer and fractional parts. Floats may also be in scientific notation, with E or e indicating the power of 10 (2.5e2 = 2.5 x 102 = 250). *Note: In Python division and square root problems result in a float.

Why is it best practice to use the .copy() builtin function over the = operator?

Although you can make an identical copy of a list using the = operator it is not recommended to do so. Unlike the .copy() builtin function, making a copy via the = operator doesn't create a new memory id for the new copy. Instead both lists, orginal and copy keep the same id. This means that any changes made to one list will also be made to the other list.

What is an accumulator in Python? What data types does it support?

An accumulator is a way to collect or track the results of operations within a loop. A simple way to think of an accumulator is as a "running total" held in a variable. Accumulators support all types of data including both scalars and iterables.

What is an alternative way of copying a list that many Python programmers prefer to use?

An alternative to use the copy() function in Python is list slicing. List slicing can copy the whole list or whatever portion you would like to copy.

What is an interpreted Language?

An interpreted language is a type of programming language for which most of its implementations execute instructions directly and freely, without previously compiling a program into machine-language instructions. The interpreter executes the program directly, translating each statement into a sequence of one or more subroutines, and then into another language (often machine code).

What is an iterable? Which are the one commonly used in Python?

An iterable is any Python object capable of returning its members one at a time, permitting it to be iterated over in a for-loop. The most common iterables are strings, list, tuples, dictionaries, and sets.

What is an incrementation operator?

Any basic operator combined with the assignment operator =, like *= or +=, which denotes multiplicative and additive incrementation, respectively.

Python has a specific order for searching for the correct module in an import statement. Why is this important?

Because Python will search through built-in modules and then the local directory. This means that if there is a file called math.py in the local directory that you are trying to import, it won't be imported. Rather, the math built-in module will be imported. Therefore, it is important to name your modules differently from the built-in modules.

What is a nested list and why is it possible? Why is this important for data scientists?

Because a list can contain elements of any type, a list can also contain another list. This is what nesting means. Lists can be stored inside each other infinitely allowing for complex operations. Understanding the concept of nested lists and knowing how to maneuver them is important to data scientists because most collected data comes in nested lists.

What are the bitwise operators and why is not recommended to use them right way.

Bitwise operators can be used in place of and, or, and not, however, their behavior will not always be what you expect so it is recommended not to use them right away.

How to execute a single Bernoulli Trial with p = 0.25 in Python?

By simply scaling the number of items to choose from, in a way that the 1, or the "success" is represented 25% percent of the time, you will end up with the result 0 having a probability of and the result 1 having a probability of .

What does calculating probability mean and which probability is most fundamental and or important?

Calculating probability is attempting to figure out the likelihood of a specific event happening, given some number of attempts. The most fundamental and important probability calcululation is defined as: The probability of some event A occuring is the number of possible outcomes in that event, divided by the total number of possible outcomes in the sample space.

What is casting?

Casting is the act of converting an object from one type to another. *Note: Casting a float to an int drops the decimal. Use the round() function to round a float.

What is the field of combinatorics in mathematics and how is it applicable in data science?

Combinatorics is a field of mathematics concerned with counting the possible orderings and combinations of elements within a set, has many applications in data science, including database architecture and graph theory.

What is the notation for conditional probability?

Conditional Probability is notated by using the pipe symbol or |. The example below represents the probability of event E occuring, given that event A has occurred or will occur based on some assumption, presumption, or previous knowledge:

What is conditional probability and what is Kolmogorov's definition of conditional probability?

Conditional probability is the probability of one event occurring with some relationship to one or more other events. That is, the conditional probability of A given B is the quotient of the probability A intersect B , divided by the probability of B. This can be visualized as limiting the sample space to only outcomes in which B occurs, and considering it our new sample space. The numerator accounts for all outcomes of event A which exist in our new, restricted sample space; this numerator is simply the intersection of A and B.

What are DeMorgan's Laws?

DeMorgan's laws are a pair of transformation rules which are both valid rules of inference. The rules allow the expression of conjunctions and disjunctions in terms of each other via negation.

How do you remove an obj that is in a string multiple times and return as group in a list?

Define a function that takes in a string and initialize two accumulators, one for the characters seen and one for the return list. Use the .lower() method on the string to neutralize case sensitive letters. Next iterate through the string and count each character while assigning them to a count variable. Then use an if statement to filter objs that appear in the string more than once, are not in the seen list, and are not whitespace.Append these characters to the return list while multiplying each character by their respective count. Create another if statement to append the chars not seen in the character seen list to that list. Finally return the accum list.

How do you find twin prime numbers using the prime and next prime functions?

Define a function that takes in an integer as the nth number. Next instantiate a variable for 5 and a variable for 3, this is the first set of twin prime numbers. Also instantiate a counter which would count the pairs. Create a while loop that sets the variable for number 3 to the variable of number 5 if the pair counter is less than the nth pair. Next, right under the previous line, call the next prime function on the variable for number 5 and set it to itself. Right under that set an if statement that increments 1 to the pair counter if the variable for 5 minus the variable for 3 equals 2. Finally get out of the while loop and return the 3 variable and the 5 variable inside a list.

How is division different than the other arithmetic operators? What are the different operators for division in Python?

Division in Python is more complex than the other operators. Regular division "/" always returns a float unless indicated otherwise. To get the remainder you would use the modulo "%" operator. To do division without the remainder use floor division "//". Note that floor division does not round up the result. You'll need to use the round() function to get a round answer.

What does a docstring do and how is it normally broken up?

Docstrings are your way of communicating with the user of that function (which will most likely be you). A docstring should be broken up into (at least) three distinct parts: 1. Description - A short description (2 - 3 sentences) describing what the function does. 2. Parameters - A list of the parameters, what type they should be, and a small (1 - 2 sentence) description of that parameter and how it is used. 3. Return - The type(s) and a short description of the object(s) the function returns

How to iterate multiple lists in parallel?

Don't forget to create a accumulator list before hand!

How to iterate multiple lists in parallel using zip object? What are some key things to remember?

Don't forget to create a accumulator list before hand! It is also very important to remember that the iteration will stop when the shortest list finishes.

What is the general multiplication rule?

The General Multiplication Rule provides a means of calculating the probability of an intersection regardless of whether the involved events are independent or non-independent.

How do you find prime numbers?

First create a function that takes one argument (integer). Create an if statement in the functions body that returns False if the argument equals to 1. Next create an else statement with a for-loop in range(2, int(n**.5)+1) for every divisor. Under the for-loop have an if statement that returns False if the argument % the divisor equals zero. Finally return True under the for -loop.

How do you create a function that can return the index of a list with the object of the list?

First create a list then create a function with one parameter (this is the element of the list). Next, in the body of the function, you find the index of the list by using the index class method and assigning the function parameter(element of list) inside the index method parenthesis. To finish the function you will assign this statement to a new variable and return that variable at the end. Now you any element of the list that you pass through the function will return the index of that element in the list.

How do you find the next prime number using the a prime function?

First create function to find prime numbers. Next define a function that takes an integer as its argument. Next create a counter that equals the argument plus 1 (this is the next prime number). Create a while loop that calls the prime function on the counter while it equals False. in the while loop's body add 1 to the counter while it is running. Finally return the counter under while loop.

How do you count objs in an iterable with a defautdict?

First import the default dictionary from the collections module the instantiante a variable and set it to defaultdict called an int. Next iterate through the iterable object and increment 1 for every obj as they are passed through the dictionary.

How to calculate the 5 point summary in Python?

First import the percentile function from the numpy module. Next call the list on the percentile function for q1(25), median(50), and q3(75) then unpack it to the each variables respectively. For the min and max call both functions on the list and unpack both to variables of the same name. Finally return all 5 points(variables).

How do you change the position of variables in a greater or less situation using the assignment = operator?

First set the order of variables by using an if statement that identifies which of the variables is greater or less than the other. For the body of the if statement you assign the variables to themselves in the way you want them to be arranged. This becomes useful in the Greatest Common Divisor function.

What is a pseudo-code for performing an integer accumulator?

First you instantiate a variable at an integer and create the list that we will be looping through. Next we loop or iterate through the list of numbers. For the body of the loop we set the accumulator to be its previous value plus the current value. Finally we print the accumulator to check on the result. Note: that you can also use the range function instead of the list. Remember that the last value is non inclusive.

What is a pseudo-code for performing an integer accumulator with a filter?

First you instantiate a variable at an integer and create the list that we will be looping through. Next we loop or iterate through the list of numbers. For the body of the loop we use an "if" conditional statement (the filter). We use this statement to check for the value type we are looking for. If we are looking for an integer we use the isinstance method. In the next line we set the accumulator to be its previous value plus the current value. Finally we print the accumulator to check on the result.

How does writing docstrings correlate with TDD?

Forcing yourself to write the docstring for a function prior to writing the code for the function can not only serve as a small introduction to TDD, but can also serve as form of self-control; ensuring that the description of your function is only 2 or 3 sentences will help ensure that your function doesn't become unweildy.

What does certain or impossible mean in statistics?

If a specific outcome is guaranteed (for example, if both sides of a coin are heads, the outcome is guaranteed to be heads), then we refer to the outcome as certain. Lastly, if a specific outcome can never occur (as getting a tails on the aforementioned coin flip), the outcome is formally referred to as impossible.

What is a sample space?

If the outcome of a random experiment is unknown, but all of the possible outcomes are predictable in nature, then the set of all possible outcomes is known as the sample space and is denoted S. S represents every possible outcome of a random experiment.

What happens when you change the value associated with a variable? How does the function id() play a role in this?

If you change the value of a variable then the memory reference changes if the the object is immutable. If the object is mutable the memory reference stays the same. The id() function is used to return an integer representing the unique memory location for the value.

How do you import a specific function from a module instead of the whole module?

If you don't want to import the whole module and just want to import a specific function, you can use the statement from module import function. For example, to import a function that returns the square root of the argument, you can use the following line of code: *Keep in mind that doing this renders the dot notation statement as you can only use when importing the whole module.

How is a dictionary used as an accumulator?

If you have a list of tuples then you can you can unpack into a dictionary. Most of the operation will be the same except for when you iterate through the dictionary which should just how you assign keys and values to a dictionary. dictionary[tuple[key index]] = tuple[valueindex]

What is boolean flag in python? What is the logical concept of a flag in coding?

In Python a boolean flag is a flag that uses True or False. Although you can use any data type as a flag, using a boolean is more convenient due to their duel nature. You can think of a boolean flag as an on and off switch that works in conjunction with a loop.

What is a class method? How is it called onto the object?

In Python, everything is considered an object. A method is a function that is associated with a specific type of object, and is called using dot notation. Dot notation takes the form of <object_name>.<method_name>(). For example, my_list.append() would be how you call the append() method that is associated with my_list.

What makes data types dynamic in Python?

In Python, the type of a variable is not fixed, but changes dynamically according to the type of value assigned to it. This makes Python variables very flexible, but can also make debugging very difficult. Such dynamic type behavior is possible because Python variables do not actually store their data. Instead, you should think of Python variables as labels that point to data that Python stores and manages for you elsewhere.

What the difference between a literal and non-literal string?

In Python, the word literal is used to refer to a bare scalar type, i.e., "this is a literal string", vs not_literal = "this is not a literal string". The difference is that the latter is referred to by a variable and the former is just a standalone string, or a string literal.

How are outliers displayed in box and whisker plot chart?

In a box and whisker plot chart outliers of a distribution are indicated as points beyond the whiskers.

When is the median a better measure of central tendency than the mean?

In circumstances where a collection has extreme outliers (specifically datasets which contain outliers which are not symmetrical) the median can be a more robust, or superior measure to the mean.

How many bins should you use when creating an histogram?

In general, using wide bins will reduce noise created by randomness in sampling. When you have fewer data points, wider bins can be preferable. Conversely, if a data set contains a relatively large number of data points, smaller bins are more likely to give the greatest precision to a density estimation.

What's the rule of thumb for keeping functions as simple as possible?

In general, you should minimize the number of parameters a function requires. As a rule of thumb, if your function takes more than five parameters, you should refactor your code. In other words, you should come up with a way to write your function so that it takes fewer arguments.

What does mutually exclusive means?

In logic and probability theory, two events (or propositions) are mutually exclusive, or disjoint, if they cannot both occur at the same time. Two events, A and B are characterized as mutually exclusive when AB = ø, that is the intersection of two mutually exclusive events is the empty set, and therefore impossible.

What's the difference between discreet probability distributions and continuous probability distributions?

In many situations, such as flipping a coin or rolling a die there is finite set of outcomes, these are called discrete probability distributions. In random experiments where there is an infinite sample space, their outcomes are modeled using continuous probability distributions.

What does permutations mean in mathematics?

In mathematics, a permutation of a set is, loosely speaking, an arrangement of its members into a sequence or linear order, or if the set is already ordered, a rearrangement of its elements. The word "permutation" also refers to the act or process of changing the linear order of an ordered set.

What is the Cartesian Product?

In mathematics, specifically set theory, the Cartesian product of two sets A and B, denoted A × B, is the set of all ordered pairs where a is in A and b is in B.

What is an event in probability theory?

In probability theory, an event is an outcome or defined collection of outcomes of a random experiment. Typically, events are represented with a capital letter from the beginning of the alphabet, though there are some exceptions to this, such as the sample space as defined below.

What is the complement of a set in set theory?

In set theory, the complement of a set, A, refers to all elements not in A. When all sets under consideration are considered to be subsets of a given sample set S, the absolute complement of A is the set of elements in S but not in A.

What is the intersection of two evenets in set theory?

In set theory, the intersection of two events, A and B, is defined as a set which contains all of the elements of A, which are also in B. The intersection of events A and B can also be defined as the set which contains all of the elements of B, which are also in A. There are two common notations for the intersection of two events shown below.

What is the union ∪ of two events in set theory?

In set theory, the union of two events (A, B) is defined as a set which contains all of the sample points which are in A, and also all of the sample points which are in B. The union can be interpreted as the statement "The union of events A and B contains all sample points which are in A or B."

What is the syntax of a for loop?

In this example val is the variable that takes the value of the item inside the sequence on each iteration. Loop continues until we reach the last item in the sequence. The body of for loop is separated from the rest of the code using indentation.

What is the use if indentation in Python and what is the conventional number of spaces one should use for indentation according to the developer documentation?

Indentations are used to group code together. Although the developer documentation cites 4 spaces as the correct indentation increment it really depends on the user preference as long as the code block is uniformed.

What are independent and identically distributed experiments mean?

Independent and identically distributed experiments means that researchers must be able to perform an experiment repeatedly under identical conditions in order to have enough information to make statistical inferences.

If you are planning on using a lot of natural words in Python, what is a good rule of thumb when using strings?

It is best practice to reserve the single apostrophes for natural language words such as don't and wouldn't.

What are scatter plots used for?

It is common that a scatter plot is used to find or display relationships between variables. If it is found that one of the variable displayed is dependent on the other, convention dictates that one assigns the independent variable to the x-axis, and the dependent variable to the y-axis.

What does string concatenation means?

It means to add strings together.

What does the counter function from the collections module do?

The Counter function returns a dictionary of counts of occurrences of all the items in some collection. For example, Counter can be used to count letters in a string or words in a sentence.

What happens when you use the print function on an accumulator inside a funcion?

It prints each iteration of the loop including space and special characters, as the loop goes through the iterable. Using the print function outside the function would only print the final iteration with all the accumulated values. I can see this being helpful for trouble shooting a for loop.

What does iteration means in Python?

Iteration is the process of going through each item in a list, or any other iterable object, and repeatedly executing the same code.

What should you keep in mind when solving the 5 point summary Python?

Keep in mind that the 5 point summary in Python is slightly different than summary calculated in the traditional method. This is because the percentile calculations do not partition the data the same way, that is, given a dataset with an odd number of items, the center value is included in both the upper, and the lower partitions, giving a slightly different solution. However, both results would generally be considered appropriate as they each partition the existing data points accurately.

What do the .sort() and .reverse() methods do? How do they differ from the sorted() and reversed() methods and how does that affect how they operate.

Methods .sort() and .reverse.() have the same functionality as sorted() and reversed(). The difference is that .sort() and .reverse(), unlike the other two methods, DO change the list in place. Because .sort() and .reverse() operate directly on the list in place, they can not be chained together like the other two methods.

When is the mode the best measure of central tendency to use?

Mode is Preferable When Using Categorical Data. The mode can also be a useful descriptive statistic when there isn't one single central concentration of values.

What is a Modulo or symbol %?

Modulo returns the remainder after division. *note: if there is a float involved in the operation then Python will return a float for an swear.

How do f-strings round decimal numbers or floats?

Much like with the str.format() method, we can truncate floats with f-strings. Use :._f to designate how many decimal placements to return. Use the _ for numbers.

How do you create a function to get the index of list?

Name function after index with one variable preferable named after the index. In the body create a new variable which gets the index. Define the variable list.index(parameter). Finally return the new variable that gets the index. Now you can call this function with an element from the list and it will return its index value.

What does the None type mean in Python? What does it mean in other languages? And what are some instances where you will get the None type as an result or answer?

None describes the absence of a value, in other languages this is often referred to as null or undefined. You may encounter the None value if you forget the return statement on a function or use the print function instead of the return statement.

What is the formula for the expected value of a binomial distribution?

Note: The notation µ is often used to denote the mean or expected value of a random variable, because in general the binomial distribution represents a population or a "long-run average".

What is the formula for getting the variance and standard deviation of a binomial distribution?

Note: The notation ∂ is often used to denote the variance or standard deviation of a random variable, because in general the binomial distribution represents a population or in this case a "long-run variation".

What are some immutable properties of a tuple ?

Once a tuple is declared it cannot be change in anyway except for the mutable elements within the tuple. Because tuples are immutable, they have fewer associated methods. This also allows for tuples to save memory space making them faster to perform.

What does operator overloading mean?

Operator Overloading means giving operators extended meaning beyond their predefined operational meaning. A great example of this is string concatenation and string repetition with with the addition and multiplication operators respectively.

What are the common commands for the UNIX CLI?

PWD- print working directory- returns an absolute file path of your current location, or the current working directory.

What are probability distributions and what three primary things are they used for?

Probability distributions are a description of random variables which represent outcomes of a random experiment. Probability distributions are primarily used to define the sample space, compute and interpret probabilities of a given random experiment, and used as the basis for statistical inference.

What is Python?

Python is a general-purpose programming language used to develop web apps and software, automate operations within operating systems, and operate robots and other machinery.

Since both sets and dicts both use the curly brackets {}, how does Python differentiate the two?

Python is able to differentiate sets and dicts by the presence (or absence) of the colon : followed by a value. A set does not use a colon : while a dict does.

How do you find common characters in two or more lists WITHOUT duplicates only the first instance and return as a list?

Remember that when using "and not" sometimes you have to use paranthesis.

What is the order of arithmetic operations in Python? How does Python execute operations of equal ranking?

Same as PEMDAS. Operations within parentheses take precedence, then exponents get evaluated, followed by multiplication, division, or modulo operators. Lastly, addition and subtraction operators are evaluated. Operations of equal ranking are evaluated from left to right. To change the order of operation use parenthesis.

What are scatter plott?

Scatter plots are a type of graph which utilize cartesian coordinates which typically display values for two variables for a dataset. Through the use of color, size, and different shapes, one, two, or three additional variables may be represented. In a scatter plot, each data point is represented by the intersection of the two variables with a dot (or a shape in more complex scatter plots). The first variable is represented on the x-axis, while the second variable is represented on the y-axis. Scatter plots can be used to display data which is either continuous or discrete.

How are sets created in Python?

Sets can be created by using the builtin set() or by using the curly brackets with at least one element. Curly brackets without an element {} will result in a dictionary. Note: The set() builtin can also be used to cast lists, tuples, and strings to sets.

What does the .intersection() method do?

Similar to the .union() method, the .intersection() method returns the intersection of two sets. This means that one instance of the each element that is found both sets will be returned.

How do you find the median from a collection of an even length?

Simply find the length of the collection, N, and then take the average of the values at the N/2 and N+1/2 indices.

Why would you need to convert values from the input() function?

Since the input() function outputs a str as an answer, we may need to convert the value into an int, float, or bool when necessary.

How do you apply the inclusion-exclusion principle to 3 events?

Since the union of three events overlaps two AND three times, we have to take an extra step to solve for the intersection of the three events. The first thing we do is is add all the single events then we subtract all of the two-way events. Lastly we add the we add the intersection all three events.

What are the properties of list slicing?

Slicing a list is very similar to accessing a list. Use the square brackets [ ] to access/slice the index of the list and the colon : to separete the start and stop index. examples: list[:] which access the whole list , list[start_index:] which access the selected start index to the end, list[:stop_index] which access the beginning of the list index to the designated stop index, list[index] which slices the selected index.

What does a method stub or simply stub mean in software development? How does it relate to the the pass keyword?

Stud is a line of code meant to be a placeholder for code that has yet to be written. This concept relates to the pass keyword because the pass keyword is used to "do nothing" or avoid committing to an operation. The pass keyword does exactly what the name implies. It skips any line of code that precedes it.

What are some important properties of the .append method one should be aware of?

The .append method cannot be used in conjunction with the print key because it will return None. First append list then print. Appending a list onto another list will create a nested list and you can also use the append method to increment items onto a list.

What does the class method append() do? What data type is it associated with?

The .append() method is a class method for the list data type which adds, or "appends," a new (one) object at the end of the list. Note that you can only append one object to a list.

what does the .copy() builtin do?

The .copy() builtin makes an identical copy of a list but with no association with the original. Meaning that any changes made to either the original or copy does not affect the other list.

What does the .copy() method do and why is it used often?

The .copy() method creates a copy of a list and gets assigned to a new variable. The reason the .copy() and other forms of making copies of a list are important is because most of the list methods alter the original list.

How does the .count method work with strings?

The .count method functions the same way that it functions with a list except that with a string you would use quotation marks instead of parenthesis. You can also count substrings or parts of the string.

What does the .count method do and what class type is associated with?

The .count() method is available when working with lists and strings. This method will count the number of times that the argument occurs in a list or string. Note that you can count by index by using [] and element by using quotation marks ''.

What does the .extend class method do? How does it differ from the .append() method?

The .extend() method simply adds the contents of an iterable onto the end of the iterable that it was called upon, making a single iterable. The .append() method on the otherhand only adds a single index value.

What keyword methods are used with strings to identify what type of characters are contained within the string?

The .isalnum method returns a boolean depending if the string is alph-numeric or not. The .isalpha() and .isdigit() methods return a boolean depending if the string contains ONLY numbers or letter respectively. Note: whitespace will make the alphabetic method return false, periods commas or special characters will make the numeric method return false, and space or special characters will make isalnum return false.

What do the .lower and .upper methods do?

The .lower and .upper methods are associated to the str class. They make the alphabetic string upper or lower case respectively. Note that since strings are immutable a new string is created when these methods are used on a string.

What does the .remove() class method do?

The .remove() method will remove a specific element from the list. Note that this only removes the first instance of that element. Meaning that any duplicate instance or element will not be removed.

what does the .union() method do?

The .union() method allows you to, when given two sets, to find the union of the two sets. for example, sets a and b, you can find the set union by either calling a.union(b) or, equivalently, b.union(a).

What is floor division? Or symbol //?

The // or floor division, is division that throws away, or truncates, the remainder. The answer will be a round down integer which also applies to negative numbers. *note: if there is a float involved in the operation then Python will return a float for an swear.

What are the 3 logical operators? What are the common comparison operators?

The 3 logical operators are and, or, and not. They result in a True or False boolean. The common comparison operators are <, >, <=, >=, ==, and !=.

What is the Bernoulli distribution?

The Bernoulli distribution is named after Swiss mathematician Jacob Bernoulli, and it represents random variables which consist of a single trial that has two possible outcomes. Typically, these outcomes are labeled as either a "success," or a "failure." This single trial is referred to as a "Bernoulli Trial." Successes are denoted with the value 1, and failures are assigned the value zero.

What is the IQR and how do you find it?

The IQR describes the middle 50% of values when ordered from lowest to highest. To find the interquartile range (IQR), ​first find the median (middle value) of the lower and upper half of the data. These values are quartile 1 (Q1) and quartile 3 (Q3). The IQR is the difference between Q3 and Q1.

What is the The Law of Total Probability?

The Law of Total Probability allows you to use the information you have to draw conclusions about less accessible events. The law of total probability simply calculates the probability of events based on the sum of probabilities for several underlying disjoint events. Note that the set of disjoint events are mutually exclusive and when unioned together perfectly construct the event. The set of disjointed events are known as a partitions, or it can be said that these events partition the sample space.

When is the mean preferable over the median?

The Mean is Preferable in Large Datasets with Few Outliers. These are situations in which there are a large number of items in the collection, and there are not any outliers (or the outliers are symmetric). Also, inferential statistics are largely built upon measurements of the mean, so it is the statistic which is used most often.

What does the abs() function do?

The abs() function returns the absolute value of a number.

What does the all() function do?

The all() function returns True if all items in an iterable are true, otherwise it returns False. If the iterable object is empty, the all() function also returns True. Think of it as doing a and logic statement operation.

What does the any() function do? When would this function apply?

The any() function returns True if any item in an iterable is True and returns if False if all items are False or the iterable is empty. This function is handy when searching large data structures for a Truthy value or flagging a Truth value when it is collected.

what does the as keyword in Python do?

The as keyword is used to create an alias. *In the example above, we create an alias, c, when importing the calendar module, and now we can refer to the calendar module by using c instead of calendar.

What methods are used to add and remove elements from a set?

The associated methods to add and remove elements from a set are .add() and .remove().

What is the law of large of numbers?

The average of the results obtained from a large number of trials will be close to the expected value and will tend to become closer to the expected value as more trials are performed. Previously, in the lesson for discrete random variables, the expected value was described as a long-run average. The law of large numbers describes this interpretation.

What does a backlash \ do in python?

The backlash \ in Python is a escape character. This means that whatever character is placed after a backlash, it becomes an ordinary character. In the example photo you can see that the backlash turns the " into an ordinary character. Naturally the " would have ended the string early.

What is a bool in Python?

The bool is a special type that can only take one of two values, True or False. It can also be represented using the integers 1 and 0, for True and False respectively.

What are the common uses of the break and continue keywords? Why would you want to use these keywords?

The break and continue are commonly used within loops to either bypass some code or exit the loop itself. There are a number of reasons you may want to do this, either to optimize your code, or to prevent further or unnecessary calculation.

How does chaining methods work and what should keep in mind?

The chaining method is a way to call two methods on one object. The placement of the method is matters so keep that is mind. It's also important to remember that although chaining may save time and space, it can also hinder a codes readability.

What does the choice function from the random module or random.choice() do?

The choice function is great for picking out a random element from a sequence.

What makes the collections module so useful?

The collections module is useful because it provides specialized containers that are not found in the Python standard library. Some of the available containers are Counter, named tuples, deques, OrderedDict, and defaultdict.

What are the common mutable objects in Python?

The common mutable objects in Python are byte array, list, set, and dict.

What does the continue keyword do? What is an important thing to be aware of?

The continue statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration. *Remember that the placement of the continue key with the function body is important.

How does the inclusion-exclusion principle account for the overlap of multiple events?

The darker shaded region on a venn diagram visualizes the overlap of each event, portraying the area to be counted twice. To account for this, when calculating A Ú B, simply subtract AB from P(A) + P(B).

What does defaultdict do?

The defaultdict acts exactly like a dictionary but will not raise a KeyError. This is because a defaultdict gets initialized as an empty dictionary that will default to some value if no corresponding value is specified for a given key. This default value can be an empty list, the integer 0, an empty string, or any other data type.

What does the del keyword do? How does it differ from the .remove() class method?

The del keyword is used to delete objects. In Python everything is an object, so the del keyword can also be used to delete variables, lists, or parts of a list etc. Unlike the .remove() class method, del removes objects by using the index instead of the matching element name.

What does the difference method do?

The difference method compares two sets and returns a set of elements that are in one set and not the other and vise versa. For two sets A and B, a.difference(b) returns a set of elements that are in set A but not in set B. Similarly, b.difference(a) returns the elements that are in set B but not in set A.

What are the domination laws in set algebra or the universal and null sets?

The domination laws refer to both the universal set, as well as the null set. The universal set, is a set which contains all objects or elements and of which all other sets are subsets. A universal set that has already been referenced in this course is the sample space of a random experiment. The null set is what you may imagine it to be, and is also often called the empty set; this is a set which does not contain anything.

How does Python denote the end of a code block?

The end of a statement in Python is the end of the line. *Note: the ; symbol can also be used to denote the end of a statement but is not common practice.

What does the enumerate method do? What is its syntax? What are it's parameters?

The enumerate() method adds a counter to an iterable and returns it. Its syntax is enumerate(iterable, start=0). The first parameter, iterable, is a sequence, an iterator, or objects that supports iteration. The second parameter, "start", is where the counter would start. This is an optional parameter which is set to ''0'' by default. The last thing to keep in mind is that the enumerate function returns an enumerate object. That means that in order to print the enumerated list you must wrap it around a the list function.

What is the equality of two events?

The equality of two events can be determined through the examination of inclusion. If an event A is a subset of event B and B is also a subset of event A; it can be determined that the events A and B are equal. See below for an example.

How do nested for loops with one nested list work?

The first for loop iterates through the outer or main list. the second for loop iterates through the inner lists using the iterable object of the out list. When printed the inner lists are number like an index or counter with the out list repeated by the value of each inner list.

What's the common code structure for list accumulators? What's another name used for list accumulators?

The first thing to do when writing a common list accumulator code is instantiate an empty list. Next iterate oven a given list. In the body of the function perform operation over the iterator if any. After your done with the body jump to the next line to append the output to the accumulator.

What are two different ways to replicate the len() builtin function?

The first way to replication the len function is by looping through the iterable and adding one to the counter for every character. The other way is by making use of the index position using the enumerate function then adding one to the enumerate index for every character just like the counter option.

What is the 5 number summary?

The five-number summary is a set of descriptive statistics that provides information about a dataset. It consists of the five most important sample percentiles; the minimum, the lower (first) quartile: Q1, he median, the upper (third) quartile, and the maximum which are often expressed as (min, Q1, median, Q3, max).

What does the keyword from do in Python?

The from keyword is used to import only a specified section from a module.

What does the global keyword do?

The global keyword allows a variable in the global scope to be modified in the scope of or within a function. Once the variable is changed within function using the global keyword, it becomes available outside of the function with the new value.

Since variables aren't values in themselves and only reference the location of a value. What does the id() function do?

The id() function shows the location associated with the value. As the value is modified so is the location.

What does the import keyword in Python do?

The import keyword is used to import modules.

What is the inclusion-exclusion principle and what is its definition?

The inclusion-exclusion principle provides a way to calculate the union of two (or more) events. This is an especially helpful tool when it comes to calculating probabilities of events. Given two events A and B, and their respective probabilities, they cannot be simply added to calculate the union, because the items in the intersection of the two events will be counted twice. The formula to find the

How do you get the index of a list?

The index() method returns the position at the first occurrence of the specified value. The syntax used to find the index is list.index(elmnt) which can be assigned to a new variable with the = operator.

What's the involution or double complement law in set algebra?

The involution law covers situations where there is a double-complement.

What does the isinstance() function do?

The isinstance() function is basically the same as the type() function. Except that isinstance() is faster to execute and considers inheritance. The isinstance() function returns True if the specified object is of the specified type, otherwise False.

What does the .items() method do? How is it useful?

The items() method returns a view object that displays a list of a dictionary's tuple pairs in (key, value) format. It also allows a for loop to iterate over a dict. Note: order is not guaranteed.

What does the len() function do? What are some important things to keep in mind?

The len() function returns the number of items (length) in an object. some things to keep in mind. 1. The len() function also counts the spaces in a string. 2. Although list() and [] brackets can be used to instantiate a list; they can act differently in certain occasions.

How are line charts similat and different than scatter plot?

The line chart is very similar to a scatter plot in that we place our data points at the intersection of the two variables (one on the x-axis, the other on the y-axis); however, a primary difference between a scatter plot, and a line graph is that value represented on the x-axis in a line graph is ordinal in nature. The most common implementation of this concept is when we are trying to display how a variable changes over time. We represent time on our x-axis, and the variable along the y-axis.

What can you do with the math module in python?

The math module adds access to various functions and methods that are necessary to use when evaluating mathematical function in Python. The math library will work on most numeric data types with the exception complex numbers. The math module imports functions to quickly calculate factorials, absolute values, square roots, and more. It also provides values for the mathematical constants pi and e.

What is the definition of the median in statistics? How does it differ from the mean?

The median is the middle number in a sorted, ascending or descending, list of numbers and can be more descriptive of that data set than the average mean. Unlike the mean, the median can also be applied to non numerical ordinal collections of characters.

How do you access and slice a nested list?

The method of accessing and slicing a nested list is the same a single list. Think of it as layers. You would use the same method list[start:stop:step] but this time there are additional layers based on how many lists are nested.

What is the mode in statistics? And how does it differ from the median and mean?

The mode of a numerical collection, unlike the mean or median, seeks to find the item with the greatest frequency Instead of finding the center of a collection. In other words, the mode describes the value that occurs most often. The mode can also be apply to collections that are not of numerical value unlike the mean.

What are the most common notations for the mean of a collection in statistics?

The most common notations for the collection of a mean in statistics are: μ - The lowercase greek letter mu is the standard notation for a population mean. x¯ - Pronounced "x-bar" is the standard notation for a sample mean. X¯ - Capitalized x-bar is a common notation for sample mean, where X is a random variable.

What is the most important characteristic of a set?

The most important atribute of a set is that it does not take any repeating elements. So any element that is repeat will only be counted once. This can be very useful when useful when using the set() builtin with an iterable that has repeating number. It can be an easy way to filter numbers.

What is the Multiplication rule for independent events?

The multiplication rule for independent events relates the individual probabilities of multiple events to the probability that they all occur. In order to apply this rule, one must first determine that the events are independent. Secondly, it is necessary to have the probability of each event to complete the calculation.

What is the property of the not operator?

The not operator negates what comes after it. If what follows the not is true, the whole statement will return False. If what follows is False, the statement will return True.

What does the pop() method do? How does it effect the list it is called on? What can you do with the value that has been popped from the list?

The pop() method removes the last value in a list unless a specified index is given list.pop(index). Using the pop() method will change the list in place. The popped value can be stored in a new variable.

What is the use of the print() function? How does it differ from the input() function?

The print() function takes the value passed into it and writes that value to the console. This can be very useful when verifying that your code is working properly. The input() function accepts character input from the keyboard and prints the message it is passed as a prompt.

What is the variance in statistics and what are the two types?

The purpose of the variance AND the standard deviation in statistics is to express an easily interpretable measure of spread in a collection. There are two types of variance; one for the population that is averaged by dividing by n and one for the mean that is averaged by dividing by n-1

How do you import a python file script?

The python file that you import is also a module because, by definition, a module is any python file. You can import python files by using import filename if the python file is saved as filename.py. Then you can use functions defined within filename.py using dot notation (filename.function_name()).

What does the radint function from the random module or random.radint() do?

The randint function will generate an integer in a given range where both the lower and upper bounds are included.

What is the random variable probability distribution? What function belongs to each variable?

The random variable's probability distribution is a way to consider how the probabilities differ across the different values that the random variable can take on. The two types of random variables lead us to two different but related types of probability functions: the probability mass function (PMF) for discrete variables, and the probability distribution function (PDF) for continuous variables.

Why is the range function normally used in conjunction with the list type? Why is this important to a data scientist?

The range function is normally used in conjunction with the list type because the range function returns a generator-like object that only prints the output on demand not a list. This is important to data scientists because it makes creating a list conveniently easy instead of typing each number.

What does the range function do? What are it's parameters and syntax?

The range() method returns an immutable sequence of numbers between the given start integer to the non-inclusive stop integer. The syntax is range(start, stop, step*optional). Note that the range function normally has to be wrapped around an iteratable like a list, set, or tuple.

Why are mutable objects within an immutable tuple able to be changed?

The reason a mutable object can be changed within a tuple is because a tuple holds references to all the individual objects it is composed of. The references to these objects can't change, but if the object is mutable, the object itself can change without the reference changing. None of the element id's change, meaning that the reference to the list held in the tuple did not change when we changed the list.

Why would someone choose to use the .sort() and .reverse() methods over the sorted() and reversed() methods?

The reason to use .sort() and .reverse over the other two methods is if you don't need the original list and or if you want your code to be more memory efficient by not making copies of the original lists.

What does the replace() method do? What is an important attribute of this method you should be aware of?

The replace() method replaces a specified part of a string with a substring. This method has an optional count argument that can limit the number of times a string will be replaced.

How many events can there be a union of in set theory?

The union of events is not limited to only two events, in fact, given an infinite sample space, there can be an infinite number of unions.

What are some attributes of the reversed() function?

The reversed() function returns the reversed iterator of the given sequence. Keep in my mind that 1. The reversed function returns an iterable object, it does not return a list. So you have to wrap around a list in order to view the list. 2. The reversed() function is a reversal of the list NOT a reversed() sort(). To reverse sort use sorted(list, reverse = True)

What is the standard divation and why is it helpful?

The standard devition is simply the square root of the variance. We do this to convert the varience result into the original unit for readability.

Which module in Python solves for the mode?

The stats.mode function from the scipy module can be used to find the mode. It will return two np.arrays (a list-like data type from numpy), the first is the mode, the second is the relative frequency for each item in the first array. If there is more than one mode in a collection, the scipy.stats.mode() returns the mode with the lowest value.

What does the step parameter do when slicing a list?

The step parameter is by default set to one but if you would like to count by a different number then you would include one extra colon to the list slicing technique. Example: list[start:stop:step] or list[::] and etc...note: that the step parameter can count forward or backwards with a negative index.

What does the str.format() method do? Why is it superior to casting and concatenation?

The str.format() allows for insertion of variables into a string without having to cast a variable into a string or needing to use string concatenation. The basic syntax for using the .format() method uses curly braces to insert variables. You can also specify the order in which you want the variables to be evaluated within the curly braces by specifying the index of the variable as it is passed into the str.format() method.

What are two very common string methods of which you'll need to have a working knowledge of ?

The str.split() method splits a string into a list of strings, and the str.join() method concatenates a list of strings into a string.

Why does the starting value of a product accumulator differ from the starting value of a sum accumulator?

The sum accumulator can be set to any number because addition is always the same no matter what the starting number is. This is the not the case for a product accumulator because anything multiplied by zero equals zero. This means that if the list or the accumulator contain a zero the answer will be zero.

What does the sum() function do? What are some important things to keep in mind? How do you sum up a list that contains both numbers and strings?

The sum() function calculates the sum of all the elements of the passed in list. Note that the sum() function works with lists that contain only numeric-typed data. You can get around the only numeric-type restriction by running a for loop with conditional statements.

How would you add new items to a dictionary?

The syntax recommended for adding new items to a dict is using the splice method on the dict but instead of the index put the name of the key and set it to the value. Remember that the key values must be unique. If it is not then it would just replace the key previous key in the dict that has the same name.

What does the term Syntactic Sugar mean in Python?

The term Syntactic Sugar refers to the refinement of code by making it more clearly, concise, or in an alternative style that some may prefer. This is a skill that is learn overtime as you become an experience coder.

What are the three common skewed histograms?

The three common skewed histograms are Symetrically distributed. left-skewed, this is also commonly referred to as negatively skewed. The final skewed histogram is right-skewed, and this is also referred to as being positively skewed. All of these plots are uni-modal; in other words, there is a single concentration of values.

What are the ways of making a copy of a list? What is a bad example of making a copy of a list and why?

The three common ways of making a copy of a list is through the .copy() , list() , .extend, and list splicing methods. One way to NOT create a copy of a list is through assigning a known list to a variable without using the mentioned methods. This is because Python will refer the new variable to the original list and any changes made to one of the variables will affect the other.

What are the two types of comments in Python and what are they used for?

The two comments used in Python are #line comments and ''' '''block comments. They are used to send a message to someone reading your code, exclude some code snippet from running, provide function, class, or module documentation, leave TODO statements in your code, for later development

What are the two common ways to remove members of a dictionary?

The two common ways to remove members from a dictionary are the .pop() method and the del builtin key. Note that both the key and value are removed but the .pop() method has the extra functionality of being able to store the popped value.

What are the two common for loop patterns?

The two element for loop patterns are "for element in lst: print(element)" and "for i, element in enumerate(lst): print(i)"

What should ket note to remember about the Bernoulli distribution?

The two outcomes are not required to be equally likely but they must sum up to 1 because they are collectively exhaustive (cover all possibilities in the event space; there is no "option 3") and mutually exclusive (the outcome of a trial must be one or the other, not both; there is no "success and failure").

What are the two range patterns of a for loop?

The two range for loop patterns are ''for i in range(low, high):" and "for i in range(len(lst)): print(lst[i])". Note that to iterate through indices you must use the range and len for loop pattern.

What are the two tuple methods? What do they do?

The two tuple methods are count and index. The count method will return how many times the parameter passed into the method call occurs in the tuple. The Index method will return the index where the parameter passed into the method call occurs in the tuple. However, if an item appears multiple times in the tuple, only the index of the first occurence of that item will be returned.

What is the type function?

The type() function is one way to explore the type of an object in Python. It returns the type of the object passed through the function.

What is the utility of casting a string to a list since you can iterate through both a list and a string?

The utility of being able to cast a string to list is that it allows you to get around strings immutability property. You can covert a string to a list, make the changes needed, then turn back into a string by using the .join() method.

How do you make a copy of a dictionary?

The way you make a copy of a dictionary is the same way you make a copy of a list. Just like with a list common practice to make a copy of a dictionary when it is passed through a function to avoid altering the original dictionary.

What are while loops in Python?

The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true. We generally use this loop when we don't know the number of times to iterate beforehand.

How does a box and whisker plot display skewedness?

The whisker would be displayed horizontally and the skewedness would be fuller in the side that it leans. Even on both sides when is symmetric.

What's a parameter and a argument? What is the difference of the two?

The word parameter refers to the variables of a function. The word argument refers to when a specific value is assigned to a function's parameter. Function parameters are the names listed in the function's definition. Function arguments are the real values passed to the function.

What does the zip object do?

The zip object can take any number of lists and allow you to iterate over them simultaneously with ease. You can even iterate over lists that aren't the same length, but be careful because the iteration will cease as soon as the shortest list is exhausted.

What role does unpacking play when iterating through multiple lists with the zip function?

The zip object or function has to unpack the lists in their iterator variables in order to iterate through them at the same time. The first part, for a, b in is an example of unpacking. The zip object produces elements from the lists, which are unpacked into the iterator variables a and b in the order that the lists are passed into the zip object.

What is the commonly used notation for the mean in statistics?

There is no absolute consensus on the notation for median in statistics, but the x˜ (Lower-case x with a tilde over the top of it is often used to denote the median).

Is there any difference between a float accumulator and an integer accumulator? What is a key thing to keep in mind?

There is no difference between performing a float and an integer accumulator. However; it is common practice to set the accumulator to a float if you know in advance that the answer will be a float. Knowing in advance aids in the readability of the code.

What do the .keys() and .values() method do?

These methods return keys and values respectively. Note: when checking membership you do not need to use the .keys() method since it is applied by default. For values you must specify the .values() method.

There are also a number of ways that an expected value can be interpreted?

They are commonly interpreted as a long-run average. That is, if one were to run the experiment represented by our random variable repeatedly, and then average the outcomes of those experiments the result would be approximately equal to the expected value. The expected value can be interpreted as the population's mean when the probability distribution is representing a population. The expected value can be interpreted as a weighted average of the possible values of a random variable.

What do the enumerate and zip functions have in common?

They iterate through both list and strings and return a tuple for an answer.

What does the optional maxsplit argument of the .split() do?

This argument stops the split method after the specified number of splits. For example, if maxsplit=1, the string will be split at the first occurrence of the delimiter and then the method will terminate, returning a list of two elements.

What does the .split() method do?

This method splits a string at each occurrence of a specified delimiter and will return a list with each split substring. If no argument is specified, the default delimiter will be a space. It is important to note that the delimiter will be omitted from the final list.

How do you get a specific value out of a dictionary?

To get a specific value from a dictionary you must use the enumerate function to assign the index of the iterable object to an empty dictionary's key. Once you iterate through the object assign the dictionary obj to the value. Note that you can even assign a name to each individual index.

How do you setup a counter that searches for more than one number?

To have a counter search more than one number simply set the counter to the number + 1

How do you implent bessel's correction to the variance and standard deviation?

To implement Bessel's correction you simply add the ddof (delta degrees of freedom) optional argument to the variance or std formular and set it to -1.

How do you loop through an enumerate object? What are some examples?

To loop through an enumerate object you wrap the iterable around it and follow the the usual for loop procedure. Examples of for looping through an enumerate object are. 1. basic looping = for item in enumerate(lst). *note that calling the element returns a tuple if index is not instantiated. 2. looping with a counter = for i, item enumerate(lst) 3. looping without a 0 index = for i, item in enumerate(lst, start_index)`

How do you use conditional probability to test for independence?

To show that two events are independent it must be shown that the probability of event A occuring remains the same whether or not event B has occured.

How do you slice into an individual string index?

To slice into an individual index of a string simply use the [:] after the string. The colon act as the divider for the starting or finishing point. There are multiple ways to access with both positive or negative numbers so play the with position.

What is the snake case naming convention commonly used in Python?

To write something in snake case, simply use a _ anywhere you would use a space and make sure every word is lower case. For example, this_is_a_variable. *Note: you can't begin a variable name with a number.

What's the definitaion of independence in probabilitity?

Two events are independent, statistically independent, or stochastically independent if the occurrence of one does not affect the probability of occurrence of the other.

In Python what is type inference and how does it differ from from other coding languages?

Type inference means that unlike other languages, in Python you do not have to specify the type of data of a variable. Python will infer the data type which can be called by using the type() function.

What does underflow mean?

Underflow is when the result of a calculation in a program is a number of smaller absolute value than the computer can represent in memory on its central processing unit (CPU).

What makes the median different from the mean and when should it be used?

Unlike the mean, the median is resistant to outliers. This is because the mean takes into account all the values in a dataset including extreme outliers. The median on the otherhand counts each data point as an individual unit instead of the cummulative values which can be offset by disrupted by values of extreme outliers.

What does unpacking mean and do? When is it convenient to use?

Unpacking means assigning an iterable of values to a tuple (or list ) of variables in a single assignment statement. Note: you can unpack multiple lists at the same time by accessing the list index, list[index]

What's a unique feature of using a set as an accumulator?

Using a set as accumulator allowes you to accumulate only one instance of a list or iterable. Although this doesnt seem like a big deal it is a shorter way to get rid fo duplicate elements. Remember that you can't just use {} to instantiate a set accumulator due to the dict property. Instead instantiate with this format set()

When does using a comma as a delimiter instead of whitespace come in handy?

Using comma as a delimiter is handy because it helps parse over cvs (comma separated values) files. Note that you still have to convert the list of strings into int or float. Also important to remember is that you may also find alphabetic values in cvs files.

How to perform a single Bernoulli Trial in Python?

Using the .choice() method, will randomly (with equal probability) choose an item from the iterable that you use as a parameter, in this case a list, however, random.choice(range(2)) would function identically.

How is a infinite loop created and how do you exit it?

We can create an infinite loop by letting a while run true without an exit statement. If the condition of a while loop is always True (boolean flag), we get an infinite loop.

What makes set unique when used as an accumulator?

What makes a set unique is their ability to remove any duplicate values on the iterable they are called on. This has the benefit of simplifying code when creating a collection of items that can't have duplicates.

What are random variables?

When the outcome of a random experiment is a numerical value, the outcome is called a random variable. A random variable can also be interpreted as a numerical value that's determined by chance. Random variables are commonly notated through the use of capital letters from the end of the alphabet. Most commonly a random variable will be denoted as X or Y. That is, the value of X or Y, our random variables, will not be determined until the experiment is carried out.

How is str.format() used when rounding decimal numbers?

When working with decimals, you can specify rounding by inserting :._f into the curly braces, where _ is the number of decimal places to which the value should be rounded.

Why don't keywords such as del, .pop, or value reassignment work with a string?

While strings are sequences, some sequence methods and statements like del and value reassignment don't work, because strings are an immutable data type.

How do you find the mode?

You can find the mode by making a frequency table of all the numbers or characters. To determine the mode of large collections statistical software, programming languages, or analytics software are typically used to determine the mode.

What else can you do with variable substitution, or specifying the index as it passes through the str.format() method?

You can give substituted variables aliases and they can be inserted any order when declaring the string.

How do you import variables from a python file?

You can import variables defined in your python script the same way you would import a file script or function. The only difference is that you would use module_name.variable_name to access the variable.

How do you declare a dictionary? How about an empty dict?

You declare a dictionary like you would declare a set by using the curly brackets. The important thing to remember is that you need to put the colon : between the key and value to make the instance a dictionary. To declare an empty dict use the dict() constructor or assign a pair of empty curly brackets to a variable.

How do you import specific functions from your own files?

You import specific functions from your own file the same way you would import it from a python module.

How do you iterate through two accumulators?

You iterate through two accumulators the same way you you iterate though one accumulator except you'll be adding an additional statement for the additional accumulator.

What are some common ways that you may encounter or use the None type as data scientist?

You may use the None type as a placeholder by casting a variable to None. This would avoid getting a syntax error while you continue to work on code. You will encounter the None type when going through data that could not be collected or data that is not relevant like blank spaces and NA which will be converted to None.

When should you use the break keyword.

You should use the break keyword to exit a for or while loop when further computation is no longer necessary, and to avoid or exit an infinite loops when using while.

Since strings are immutable and their content can't be changed, what's a workaround to updating a string and in which occasion will this be useful?

a workaround to updating an immutable string is to concatenate the string that needs to be updated with with the new string which has the update. The string that needs updating should, if needed, slice the error. This useful information such as someones name needs to be fixed in a database.

How do you turn two lists into a dictionary?

create a dictionary accumulator where you will be collecting the key and values of the two lists. iterate through one of the lists using the len(range()) statement. Set the dictionary to a key for one list and a value for the other list using the object you iterate it through.

Why are dictionaries important?

dictionaries provides a simple and elegant structure through which to analyze and contain data whether it be counting the occurrences of letters in a paragraph, viewing counts in a distribution, or examples where you have to collect values to an index. NOTE: that the placement the key and value is not guaranteed when using dictionaries.

Why are dictionary accumulators useful?

dictionary accumulators are useful because you can accumulate more than one value in one object. For example, you can use a dictionary accumulator as a counter if you want to keep track of how many times the words the, this, and then, occur inside a text document. You can set each key to be the strings 'the', 'this', and 'then', and then set each value to be 0 which you can then use to count the occurrences as you iterate through the document.

What is a key rule to remember about the inclusion-exclusion rule and dealing with multiple events?

for any number of events, the probability of all intersections which involve an odd number of events (including the singular probabilities) are added, and the probabilities of all intersections which involve an even number of events are subtracted.

What doses mutability means in Python? Which objects are mutable and immutable?

mutable objects can change their state or contents and immutable objects can't change their state or content. Immutable Objects : These are of in-built types like int, float, bool, string, unicode, tuple. In simple words, an immutable object can't be changed after it is created. Mutable Objects : These are of type list, dict, set . Custom classes are generally mutable.

What's the order of operation for logical operators?

not gets evaluated first, followed by and. or operators will be evaluated last. Bitwise operators get evaluated in the same order but a bitwise operator will always be evaluated before a logical operator. *Note that parenthesis should be evaluated first just like in arithmetic order of operation.

What is the difference between a population and a sample dataset?

population represents all of the possible data points or observations from a set of data while a sample does not represent every possible observation, instead you would take a random dataset from the total population and infer the mean from that sample.

What is the difference between printing and returning?

print just shows the human user a string representing what is going on inside the computer. The computer cannot make use of that printing. return is how a function gives back a value. ... All functions will return a value, and if there is no return statement it will return None .

What do the functions Sorted() and Reversed() do?

sorted() will return a sorted version of a list, while reversed() will return the a list with the elements in reversed order. Note that neither of these functions alter the list that is used as input in place, but rather return a copy of the list that was used as input.

What's the difference between Text editors and word processors?

text editors are used to write plain text which is ideal for programming as it aids in readability. A word processor, by contrast, is geared towards writing documents like novels, essays, memos, etc.

How do nested for loops with two different lists work?

the first for loop iterates through the first list. Then you indent under the first for loop to create another for loop where the second list will be iterated through. Note that the list and single iterable item will be different.


Related study sets

Chapter 2: Global E-business and collaboration

View Set

CHAPTER 1: INTRODUCTION AND HOW CARS WORK

View Set