<jupyter_start><jupyter_text>Office Hours workshop with Anade (<NAME>)Advanced Loops & Lists in Python Interger = NumberFloat = Numbers with DecimalsString = Sequence of Characters (Words, Letters, Numbers, intergers, floats, etc)Object = All Characters (Strings and Objects have become synonymous)**Loops** = Perform a task over and over again**Range Function** = Ordered Sequence**List** = Ordered Sequence**Set** = Unordered Sequence **Conditional Statements**Equals: x==yNot Equals: x!=yLess than: x<yLess than or equal to: x<=yGreater than: x>yGreater than or equal to: x>=y<jupyter_code>#define a list, Family is the name of the list here
Family = ['Husband', 'Sister', 'Child', 'Brother']
#function that acts on each item in the list
#in this case, it prints them
#A is a made-up thing, can be anything you make up
for A in Family: #this creates the Value A (blank variable) for values in Family (a real variable, a list)
  print(A) #this tells to print the variable A, which is defined by the values in Family
#define a new variable Math, a list
Math = [7,8,9,5,4,2,1]
#this tells the variable to be multiplied by itself
for c in Math:
  print(c*c)
#this tells the variable to be added to 12
for c in Math:
  print(c+12)
#define a new variable with range function
#3 is position where range starts (so 4th because 1st is 0)
#200 is position where range ends (so 199 would be the highest number in range)
#21 is how many numbers to "skip" by in creating the range
Math2 = range(3,200,21)
#this shows what Math2 is defined as
Math2
#this tells what type of object Math2 is
type(Math2)
#we can't get the values the range defines without the for statement below
print(Math2)
#here is how we can pull the values we created in the range
for c in Math2:
  print(c)
#define another range variable
Math3 = range(2, 50, 3)
#see the values in our new range variable
for c in Math3:
  print(c)
#now do some math on the values in the variable
for c in Math3:
  print(c*c+2) #2*2=4+2=6, 5*5=25+2=27, ets
#define another list as variable Math4
Math4 = [5,6,7,7,5,7,8,12,14]
#find out the length or amount of characters or items in our list
len(Math4)
#define a variable based on the length of the other variable
NewMath=len(Math4)
#view the value of the new variable
#notice the for function is not needed
NewMath
#create a range based on the new variable
for x in range(0,NewMath):
  print(x)
#create a new variable which is a list
Family2 = ['Husband', 'Sister', 'Child', 'Brother', 'Mother', 'Father']
#view all the values in the variable
for b in Family2:
  print(b)
#break the loop after the == Conditional Statement, by placing print() function before it
for b in Family2:
  print(b)
  if b == 'Mother':
      break
#break the loop before the == Conditional Statement, by placing the print() function after it
for b in Family2:
  if b == 'Mother':
      break
  print(b)
#this is how to ignore a value in the loop
#poor mama :( she always gets ignored
for b in Family2:
  if b != 'Mother':
      print(b)<jupyter_output>Husband
Sister
Child
Brother
Father<jupyter_text>If != is present, that means the loop remains True, green light to keep going, just don't include this output<jupyter_code>#define another variable
A = 16
#a "While Loop" starts from the start of the variable
#and ends until our while is over, until A is no longer less than 40, in this case
while A < 40:
      print(A)
      A += 2
#define another variable
A2 = 60
#WARNING: this code will keep running and running and running
#because we are adding, and the conditional statement of being greater than 40 will always be True
#to stop the code, right-click and select 'Interrupt Execution'
#no heads need to roll, at least not tonight
while A2 > 40:
      print(A2)
      A2 += 2<jupyter_output><empty_output><jupyter_text>Some final definitions from AnadeWhile Loop: repeated as long as an expression is trueExpression: a statement that has a valueDo While Loop or Repeat Until Loop: repeats until an expression becomes FalseInfinite or Endless Loop: repeats indefinitely because it has no terminating condition, the exit condition is never met, or the loop is instructed to start over from the beginningAlthough it is possible for a programmer to intentionally use an infinite loop, they are often mistakes made by new programmers.Nested Loop: appears inside any other For, While, or Do While Loop<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07545887151597552, 'fraction_numerical': 0.021527305687740767, 'mean_word_length': 4.673521850899743, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '512502', 'license': 'MIT', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1283, 'n_words': 679, 'path': '9_1_20AdvLoops&Lists.ipynb', 'repo_name': 'TLeahSpencer/Loops_Lists_Wkshp', 'size': '4421'}