Code refactoring is crucial but often overlooked. It can improve the design and performance of existing code.

The Python code below takes about 14 seconds to complete. Refactor the function to make it run in less than 10 seconds. Post your answer in the comments.

import timedef getData():
arr = []
for i in range(1000*1000*50):
arr.append(i)
lo, hi = 0, 0
for x in arr:
if x < lo:
lo = x
if x > hi:
hi = x
print(lo, hi)
return arr
def timed(func):
def run():
Tstart = time.time()
func()
Tend = time.time()
Tdt = round(Tend - Tstart, 2)
print(Tdt, 'seconds')
return run
@timed
def main():
data = getData()
print('len:', len(data), 'sum:', sum(data))
main()

Code refactoring is crucial but often overlooked. It can improve the design and performance of existing code.

The Python code below takes about 17 seconds to complete. Refactor the function to make it run in less than 5 seconds. Post your answer in the comments.

import timedef getData():
arr = [5] * 1000 * 1000 * 100
for i in range(1, len(arr)):
if i % 5 == 0:
arr[i] = 0
return arr
def timed(func):
def run():
Tstart = time.time()
func()
Tend = time.time()
Tdt = round(Tend - Tstart, 2)
print(Tdt, 'seconds')
return run
@timed
def main():
data = getData()
print('len:', len(data), 'sum:', sum(data))
main()

Code refactoring is crucial but often overlooked. It can improve the design and performance of existing code.

The Python code below takes about 12 seconds to execute. Refactor the function to make it run in less than 1 second. Post your answer in the comments.

import timedef getData():
arr = []
for i in range(1000*1000*100):
arr.append(5)
return arr
def timed(func):
def run():
Tstart = time.time()
func()
Tend = time.time()
Tdt = round(Tend - Tstart, 2)
print(Tdt, 'seconds')
return run
@timed
def main():
print(len(getData()))
main()

Discovering anomalies in complex multivariate and multidimensional data can be quite a challenge. Visualizing these anomalies can be even trickier, especially if you want to keep it simple without having to go over thousands of charts to filter out issues from false positives and noise. Using statistical methods we can…

Most of you know CRM by the many advanced tools out there such as Salesforce, Capterra and Hubspot. But millions of small companies still use Excel/Word/Files/Directories to manage their accounts, invoices and projects. I have met very few individual contractors who use productivity tools/apps, even simple things like notepad apps…

Past few weeks I was obsessed with the song Mr Sandman. And been thinking of making a cat edition of this beat.

Since I couldn’t find anything decent on YouTube, it was time to have a productive Saturday!

Video Demo: https://www.youtube.com/watch?v=y7hKNtucQbg
Site Demo: https://nevolin.be/meow/
GitHub: https://github.com/healzer/MeowSynth

This code may not…

Welcome to the fourth level where we solve Python Challenges from Codr’s Ranked mode. The goal is to reach the Genius level, so join me at Codr!

Welcome to the third level where we solve Python Challenges from Codr’s Ranked mode. The goal is to reach the Genius level, so join me at Codr!

I was reading an interesting post on Reddit on product psychology, and it reminded me of the Goal Gradient Effect.

This effect tells us that:

  • The closer to their goal the more motivated people are.
  • As people get closer to a reward, they speed up to get to their goal…

Welcome to the second level where we solve Python Challenges from Codr’s Ranked mode. The goal is to reach the Genius level, so join me at Codr!

We start off with quite hard challenge. Given the function name it seems to be the doing a cross product of two…

Ilya Nevolin

Become a rockstar programmer and try to reach genius status on codr https://nevolin.be/codr/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store