Skip to content
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
11 changes: 6 additions & 5 deletions misc/worker_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ def walltime2seconds(walltime):
220343
'''
time_strs = walltime.split(':')[::-1]
seconds = 0
for period, multiplier in zip(map(int, time_strs),
[1, 60, 3600, 24*3600]):
seconds += period*multiplier
return seconds
return sum(
period * multiplier
for period, multiplier in zip(
map(int, time_strs), [1, 60, 3600, 24 * 3600]
)
)
Comment on lines -66 to +71
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function walltime2seconds refactored with the following changes:



# see derivation.ipynb for details on this function
Expand Down
6 changes: 3 additions & 3 deletions tests/Reductor/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
arg_parser.add_argument('--verbose', action='store_true',
help='verbose output')
options = arg_parser.parse_args()
count = dict()
count = {}
with open(options.input, 'r') as in_file:
for line_nr in xrange(options.start):
for _ in xrange(options.start):
_ = in_file.readline()
for line_nr in xrange(options.start, options.end):
line = in_file.readline().rstrip()
if not line:
break
if options.verbose:
sys.stderr.write('processing line ' + str(line_nr) + '\n')
sys.stderr.write(f'processing line {str(line_nr)}' + '\n')
Comment on lines -21 to +30
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 21-30 refactored with the following changes:

for word in line.split():
if word not in count:
count[word] = 0
Expand Down
4 changes: 1 addition & 3 deletions tests/Reductor/data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
for _ in xrange(options.lines):
words = []
for _ in xrange(options.words_per_line):
word = ''
for _ in xrange(options.word_length):
word += random.choice('ABCDE')
word = ''.join(random.choice('ABCDE') for _ in xrange(options.word_length))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 19-21 refactored with the following changes:

  • Use str.join() instead of for loop (use-join)

words.append(word)
print(' '.join(words))
2 changes: 1 addition & 1 deletion tests/Reductor/pickle_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
'dictionary')
arg_parser.add_argument('out', help='name of the pickle file')
options = arg_parser.parse_args()
counter = dict()
counter = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 11-11 refactored with the following changes:

with open(options.out, 'wb') as out_file:
pickle.dump(counter, out_file)