-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rick Copeland <[email protected]>
- Loading branch information
Showing
15 changed files
with
66 additions
and
51 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,5 @@ | ||
#!/usr/bin/env python | ||
def sayhello(name): | ||
print 'Hello, ' + name | ||
|
||
sayhello('Rick') |
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
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 |
---|---|---|
@@ -1,20 +1,9 @@ | ||
def sum_even_values(lst): | ||
result = 0 | ||
for index, element in enumerate(lst): | ||
if index % 2 == 0: | ||
result += element | ||
return result | ||
|
||
print sum_even_values([1,2,3]) | ||
print sum_even_values([100, 200]) | ||
|
||
|
||
def sum_even_values_alt(lst): | ||
result = 0 | ||
lst1 = lst[::2] | ||
for element in lst1: | ||
result += element | ||
return result | ||
|
||
print sum_even_values_alt([1,2,3]) | ||
print sum_even_values_alt([100, 200]) | ||
print sum_even_values([1,2,3]) | ||
print sum_even_values([100, 200]) |
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
def ascii2str(lst): | ||
return ''.join(map(chr, lst)) | ||
s = '' | ||
characters = map(chr, lst) | ||
for ch in characters: | ||
s += ch | ||
return s | ||
|
||
print ascii2str([86, 77, 87, 97, 114, 101]) | ||
|
||
def ascii2str_alt(lst): | ||
characters = map(chr, lst) | ||
return ''.join(characters) | ||
|
||
print ascii2str_alt([86, 77, 87, 97, 114, 101]) |
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
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
import time | ||
|
||
def dt_to_ts(dt): | ||
return time.mktime(dt.timetuple()) |
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
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
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,22 @@ | ||
import StringIO | ||
|
||
text = ''' | ||
The quick brown fox jumped over the lazy dog. | ||
The dog was very lazy and the fox was quite quick. | ||
''' | ||
|
||
def isalpha(ch): | ||
return ch.isalpha() | ||
|
||
def get_words_count(fp): | ||
result = {} | ||
for line in fp: | ||
for word in line.split(): | ||
word = ''.join(filter(isalpha, word.lower())) | ||
if word in result: | ||
result[word] += 1 | ||
else: | ||
result[word] = 1 | ||
return result | ||
|
||
print get_words_count(StringIO.StringIO(text)) |
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
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,5 @@ | ||
def print_centered_words(words): | ||
for word in words: | ||
print word.title().center(80) | ||
|
||
print_centered_words(['The', 'quick', 'brown', 'fox']) |
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
print 'importing mypackage' | ||
import mysubpackage |
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
print 'importing mypackage.mysubpackage' | ||
|
||
|
||
|
||
|
||
|
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