Ad

I had trouble with the kata sum of a sequence, hard-core version. After looking at the solutions, I saw that the solutions used were more mathematical/ formula based rather than computation based.
I was hoping some of you can help make my, rather simplistic, code prettier without losing efficiency.

def sequence_sum(b, e, s):
    sum = 0
    if s >= 0:
        while b <= e:
            sum += b
            b += s
    else:
        while b > e:
            sum += b
            b += s
    return sum
Debugging
Image Processing

Through experience I found that hardcoding in file names/ destinations/ quantities, etc. always lead to unknown bugs later on.

So I would really prefer having the folder source and destination as a variable/parameter.

Code
Diff
  • import os, shutil
    
    class MoveFiles:
        def __init__(self):
            self.imageFolder = "folderA"
            self.images = [img for img in os.listdir(self.imageFolder) if img.endswith(('.png', '.jpg', '.jpeg'))]
    
        def move_image_files(self, source = "folderA", destination = "folderB"):
            for img in self.images:
                shutil.move(os.path.join(source, img), os.path.join(destination, img))
    
    • import os, shutil
    • class MoveFiles:
    • def __init__(self):
    • self.images = [img for img in os.listdir('folderA') if img.endswith(('.png', '.jpg', '.jpeg'))]
    • def __init__(self):
    • self.imageFolder = "folderA"
    • self.images = [img for img in os.listdir(self.imageFolder) if img.endswith(('.png', '.jpg', '.jpeg'))]
    • def move_image_files(self):
    • def move_image_files(self, source = "folderA", destination = "folderB"):
    • for img in self.images:
    • shutil.move(os.path.join('folderA', img), os.path.join('folderB', img))
    • shutil.move(os.path.join(source, img), os.path.join(destination, img))