
import glob
import os.path
import random


def pick_random(directory, k=None):
    """Pick randomly some files from a directory."""
    all_files = glob.glob(os.path.join(directory, '*'))
    random.shuffle(all_files)
    return all_files if k is None else all_files[:k]


import glob
import os.path
import random
import re


def pick(directory, k=None, randomized=True):
    """Pick some thread files from a thread directory."""
    all_files = glob.glob(os.path.join(directory, '*'))
    if randomized:
        random.shuffle(all_files)
    else:
        pattern = '([0-9]+)\.txt'
        all_files.sort(key=lambda f: int(re.search(pattern, f).group(1)))
    return all_files if k is None else all_files[:k]

Modify to pick either randomly or sequentially
Modify to pick either randomly or sequentially

  
  import glob
  import os.path
  import random
+ import re
  
  
- def pick_random(directory, k=None):
+ def pick(directory, k=None, randomized=True):
-     """Pick randomly some files from a directory."""
+     """Pick some thread files from a thread directory."""
      all_files = glob.glob(os.path.join(directory, '*'))
+     if randomized:
-     random.shuffle(all_files)
+         random.shuffle(all_files)
+     else:
+         pattern = '([0-9]+)\.txt'
+         all_files.sort(key=lambda f: int(re.search(pattern, f).group(1)))
      return all_files if k is None else all_files[:k]
  
Modify to pick either randomly or sequentially
## Code Before:

import glob
import os.path
import random


def pick_random(directory, k=None):
    """Pick randomly some files from a directory."""
    all_files = glob.glob(os.path.join(directory, '*'))
    random.shuffle(all_files)
    return all_files if k is None else all_files[:k]

## Instruction:
Modify to pick either randomly or sequentially
## Code After:

import glob
import os.path
import random
import re


def pick(directory, k=None, randomized=True):
    """Pick some thread files from a thread directory."""
    all_files = glob.glob(os.path.join(directory, '*'))
    if randomized:
        random.shuffle(all_files)
    else:
        pattern = '([0-9]+)\.txt'
        all_files.sort(key=lambda f: int(re.search(pattern, f).group(1)))
    return all_files if k is None else all_files[:k]
