less = []
greater = []
for x in [1, 3, 4, 2, 8, 6]:
if x<3:
less.append(x)
else: # conditional statement
greater.append(x)
print("less=", less, "greater=", greater)

```
less= [1, 2] greater= [3, 4, 8, 6]
```

a=[1,2,3,]
a

b=a
b

a.append(4)
b

x = -5
if x < 0:
print("It's negative")

```
It's negative
```

if int(x) < 0:
print("It's negative")
elif int(x) == 0:
print("Equal to zero")
elif 0 < int(x) < 5:
print("Positive but smaller than 5")
else:
print("Positive and larger than or equal to 5")

```
It's negative
```

x = 0
if int(x) < 0:
print("It's negative")
elif int(x) == 0:
print("Equal to zero")
elif 0 < int(x) < 5:
print("Positive but smaller than 5")
else:
print("Positive and larger than or equal to 5")

```
Equal to zero
```

x

y

print(x)
print(y)
if int(x) < 0:
print("It's negative")
elif int(x) == 0:
print("Equal to zero")
elif 0 < int(x) < 5:
print("Positive but smaller than 5")
else:
print("Positive and larger than or equal to 5")

```
-2
5
It's negative
```

sequence = [1, 2, 0, 3, 6, 9, 2, 1]
total = 0
for value in sequence:
total += value # total = total + value
print("total =", total)

```
total = 1
total = 3
total = 3
total = 6
total = 12
total = 21
total = 23
total = 24
```

sequence = [1, 2, 0, 3, 6, 9, 2, 1]
total = 0
for value in sequence:
total += value # total = total + value
print("total =", total)

```
total = 24
```

sequence = [1, 4, None, 4, None, 5]
total = 0
for value in sequence:
if value is None:
continue
total += value
print(total) # Continue adding values while ignoring specified input "None" in "continue"

```
14
```

sequence = [1, 6, 0, 3, 5, 2, 1]
total_until_5 = 0
for value in sequence:
if value == 5:
break
total_until_5 += value
print(total_until_5) # Stop adding values once specified input "5" encountered in "break"

```
10
```

for i in range(4): # indicates numerical values 0-4
for j in range(4):
if j > i:
break # if the y coord. is greater than x, break
print ((i, j)) # coordinate values identified here

```
(0, 0)
(1, 0)
(1, 1)
(2, 0)
(2, 1)
(2, 2)
(3, 0)
(3, 1)
(3, 2)
(3, 3)
```

x = 256 # a variable x = 256
total = 0
while x > 0: #when x is greater than 0, print x
print(x)
if total > 500:
break # when x is greater than 500, break
total += x
print(total)
x//= 2

```
256
256
128
384
64
448
32
480
16
496
8
504
4
```

x = 0
if x < 0:
print("negative!")
elif x == 0:
print("Zero")
pass
else:
print("positive")

```
Zero
```

x = 5
if x < 0:
print("negative!")
elif x == 0:
print("Zero")
pass
else:
print("positive")

```
positive
```

seq = [10, 20, 30, 40] # entered a sequence of four numerical values
for i in range(len(seq)):
print("element %d: %d" %(i, seq[i])) # print integers (%d) with element name (staring at 0)

```
element 0: 10
element 1: 20
element 2: 30
element 3: 40
```

# enumerate function
l1 = ["eat", "sleep", "repeart"]
# creating enumerating objects
obj1 = enumerate(l1)
print("Return type:", type(obj1))
print(list(enumerate(l1)))

```
Return type: <class 'enumerate'>
[(0, 'eat'), (1, 'sleep'), (2, 'repeart')]
```

a = [8, 1, 2, 4, 0, 6, 2]
sorted(a)

a

print(sorted("COP2000 Python Programming")) # takes each individual character of the string and sorts it via the ASCII map

```
[' ', ' ', '0', '0', '0', '2', 'C', 'O', 'P', 'P', 'P', 'a', 'g', 'g', 'h', 'i', 'm', 'm', 'n', 'n', 'o', 'o', 'r', 'r', 't', 'y']
```

seq1 = ["Uno", "Dos", "Tres"] # ex: translation
seq2 = ["one", "two", "three"]
zipped = zip(seq1, seq2)
list(zipped)

seq3 = [False, True] # zip three sequences; zips first two elements regardless of length
list(zip(seq1, seq2, seq3)) # can zip any number of sequences

for index, (a, b) in enumerate(zip(seq1, seq2)): # takes the pair of a, b and correlates to the two sequences to join them together
print (f"{index}: {a}, {b}",)

```
0: Uno, one
1: Dos, two
2: Tres, three
```

list(reversed(range(10))) # remember that the list is from 0-9, not 0-10

def apply_to_list(some_list, f):
return [f(x) for x in some_list] # do not require this part; complex and stores information
ints = [2, 4, 6, 7, 3, 1, 9]
apply_to_list(ints, lambda x: x ** 2) # squaring is not a karat

ints = [2, 4, 6, 7, 3, 1, 9]
apply_to_list(ints, lambda x: x ** 2) #lambda makes transferring information easier

! wget "https://www.gutenberg.org/files/76/76-0.txt" -O adventures.txt
! ( head -10 adventures.txt) > adventures10.txt # large file; just taking first ten lines

```
--2022-08-31 14:26:17-- https://www.gutenberg.org/files/76/76-0.txt
Resolving www.gutenberg.org (www.gutenberg.org)... 152.19.134.47, 2610:28:3090:3000:0:bad:cafe:47
Connecting to www.gutenberg.org (www.gutenberg.org)|152.19.134.47|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 610370 (596K) [text/plain]
Saving to: ‘adventures.txt’
adventures.txt 100%[===================>] 596.06K --.-KB/s in 0.1s
2022-08-31 14:26:17 (6.05 MB/s) - ‘adventures.txt’ saved [610370/610370]
```

f = open("adventures10.txt", encoding="utf-8") # f = hook of website
for line in f:
print(line)

```
The Project Gutenberg eBook of Adventures of Huckleberry Finn, by Mark Twain (Samuel Clemens)
This eBook is for the use of anyone anywhere in the United States and
most other parts of the world at no cost and with almost no restrictions
whatsoever. You may copy it, give it away or re-use it under the terms
of the Project Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United States, you
will have to check the laws of the country where you are located before
using this eBook.
```