forked from CoreyMSchafer/code_snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
588f067
commit 2259d6c
Showing
3 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
import itertools | ||
|
||
|
||
def get_state(person): | ||
return person['state'] | ||
|
||
|
||
people = [ | ||
{ | ||
'name': 'John Doe', | ||
'city': 'Gotham', | ||
'state': 'NY' | ||
}, | ||
{ | ||
'name': 'Jane Doe', | ||
'city': 'Kings Landing', | ||
'state': 'NY' | ||
}, | ||
{ | ||
'name': 'Corey Schafer', | ||
'city': 'Boulder', | ||
'state': 'CO' | ||
}, | ||
{ | ||
'name': 'Al Einstein', | ||
'city': 'Denver', | ||
'state': 'CO' | ||
}, | ||
{ | ||
'name': 'John Henry', | ||
'city': 'Hinton', | ||
'state': 'WV' | ||
}, | ||
{ | ||
'name': 'Randy Moss', | ||
'city': 'Rand', | ||
'state': 'WV' | ||
}, | ||
{ | ||
'name': 'Nicole K', | ||
'city': 'Asheville', | ||
'state': 'NC' | ||
}, | ||
{ | ||
'name': 'Jim Doe', | ||
'city': 'Charlotte', | ||
'state': 'NC' | ||
}, | ||
{ | ||
'name': 'Jane Taylor', | ||
'city': 'Faketown', | ||
'state': 'NC' | ||
} | ||
] | ||
|
||
person_group = itertools.groupby(people, get_state) | ||
|
||
copy1, copy2 = itertools.tee(person_group) | ||
|
||
for key, group in person_group: | ||
print(key, len(list(group))) | ||
# for person in group: | ||
# print(person) | ||
# print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
letters = ['a', 'b', 'c', 'd'] | ||
numbers = [0, 1, 2, 3] | ||
names = ['Corey', 'Nicole'] | ||
|
||
|
||
|
||
people = [ | ||
{ | ||
'name': 'John Doe', | ||
'city': 'Gotham', | ||
'state': 'NY' | ||
}, | ||
{ | ||
'name': 'Jane Doe', | ||
'city': 'Kings Landing', | ||
'state': 'NY' | ||
}, | ||
{ | ||
'name': 'Corey Schafer', | ||
'city': 'Boulder', | ||
'state': 'CO' | ||
}, | ||
{ | ||
'name': 'Al Einstein', | ||
'city': 'Denver', | ||
'state': 'CO' | ||
}, | ||
{ | ||
'name': 'John Henry', | ||
'city': 'Hinton', | ||
'state': 'WV' | ||
}, | ||
{ | ||
'name': 'Randy Moss', | ||
'city': 'Rand', | ||
'state': 'WV' | ||
}, | ||
{ | ||
'name': 'Nicole K', | ||
'city': 'Asheville', | ||
'state': 'NC' | ||
}, | ||
{ | ||
'name': 'Jim Doe', | ||
'city': 'Charlotte', | ||
'state': 'NC' | ||
}, | ||
{ | ||
'name': 'Jane Taylor', | ||
'city': 'Faketown', | ||
'state': 'NC' | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Date: 2018-11-08 | ||
Author: Corey | ||
Description: This is a sample log file | ||
|
||
Okay, so this is a sample entry. | ||
I'm going to write a few more lines here. | ||
For the sake of this video, let's pretend this log file is thousands and thousands of lines... okay? | ||
|