Skip to content
This repository was archived by the owner on Oct 9, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Student/osiddiquee/lesson01/generator_solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
def intsum():
previous, last = 0, 0
while last >= 0:
if last == 0:
yield previous
last += 1
else:
sum = previous + last
previous = sum
last += 1
yield sum


def doubler():
doubled = 1
while doubled > 0:
if doubled == 1:
yield 1
doubled *= 2
elif doubled == 2:
yield doubled
doubled *= 2
else:
yield doubled
doubled *= 2


def fib():
first, second = 0, 1
while first >= 0:
if first == 0:
yield second
first = second
second *= 2
elif first == 1:
yield first
fib2 = second
second = first + fib2
first = fib2
else:
yield first
fib2 = second
second = first + fib2
first = fib2


def prime():
integer = 2
while integer > 1:
if integer == 2:
yield integer
else:
isprime = True
for i in range(2, integer):
if integer % i == 0:
isprime = False
if isprime:
yield integer
integer += 1
36 changes: 36 additions & 0 deletions Student/osiddiquee/lesson01/iterator_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python

"""
Simple iterator examples
"""


class IterateMe_2:
"""
About as simple an iterator as you can get:

returns the sequence of numbers from zero to 4
( like range(4) )
"""

def __init__(self, start = 0, stop = 5, step = 1):
self.current = start
self.stop = stop
self.step = step

def __iter__(self):
return self

def __next__(self):
self.current += self.step
if self.current < self.stop:
return self.current
else:
raise StopIteration


if __name__ == "__main__":

print("Testing the iterator")
for i in IterateMe_2():
print(i)
35 changes: 35 additions & 0 deletions Student/osiddiquee/lesson01/music.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pandas as pd

music = pd.read_csv('featuresdf.csv')

artists = [artists for artists in
music[(music['danceability'] > 0.8) &
(music['loudness'] < -5.0)].artists]

songs = [name for name in
music[(music['danceability'] > 0.8) &
(music['loudness'] < -5.0)].name]

danceability = [danceability for danceability in
music[(music['danceability'] > 0.8) &
(music['loudness'] < -5.0)].danceability]

spotify_data = list(zip(artists, songs, danceability))

sorted_spotify = sorted(spotify_data, key = lambda x: x[2], reverse = True)

print('Simple solution output: ')
for artist, song, dance in sorted_spotify[:5]:
print(song)

print('\nA much more elegant solution output: ')
''' A much more elegant solution is below '''
spotify_query = [(artist, song, dance, loud)
for (artist, song, dance, loud) in
zip(music.artists, music.name, music.danceability, music.loudness)
if (dance > 0.8) & (loud < -5.0)]

for artist, song, dance, loud in sorted(spotify_query,
key = lambda x: x[2],
reverse = True)[:5]:
print(song)
Loading