diff --git a/Python/Itertools/iter-demo.py b/Python/Itertools/iter-demo.py new file mode 100644 index 0000000000000000000000000000000000000000..b66aef3d862223a8b9269ff4bfb2977cc12e3575 --- /dev/null +++ b/Python/Itertools/iter-demo.py @@ -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() diff --git a/Python/Itertools/snippets.txt b/Python/Itertools/snippets.txt new file mode 100644 index 0000000000000000000000000000000000000000..7fbafe89f35fc1426f6cc8e0a587e465caabdf5d --- /dev/null +++ b/Python/Itertools/snippets.txt @@ -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' + } +] diff --git a/Python/Itertools/test.log b/Python/Itertools/test.log new file mode 100644 index 0000000000000000000000000000000000000000..2351d09bab441ab1428b65200b0320fea111787a --- /dev/null +++ b/Python/Itertools/test.log @@ -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? +