# Buggy code
def do_clean(ctx, three=None, python=None, dry_run=False, bare=False, verbose=False):
    # Ensure that virtualenv is available.
    ensure_project(three=three, python=python, validate=False)
    ensure_lockfile()
    installed_packages = (
        delegator.run("{0} freeze".format(which("pip"))).out.strip().split("\n")
    )
    installed_package_names = []
    for installed in installed_packages:
        r = get_requirement(installed)
        # Ignore editable installations.
        if not r.editable:
            installed_package_names.append(r.name.lower())
        else:
            if verbose:
                click.echo("Ignoring {0}.".format(repr(r.name)), err=True)
    # Remove known "bad packages" from the list.
    for bad_package in BAD_PACKAGES:
        if bad_package in installed_package_names:
            if verbose:
                click.echo("Ignoring {0}.".format(repr(bad_package)), err=True)
            del installed_package_names[installed_package_names.index(bad_package)]
    # Intelligently detect if --dev should be used or not.
    develop = [k.lower() for k in project.lockfile_content["develop"].keys()]
    default = [k.lower() for k in project.lockfile_content["default"].keys()]
    for used_package in set(develop + default):
        if used_package in installed_package_names:
            del installed_package_names[installed_package_names.index(used_package)]
    failure = False
    for apparent_bad_package in installed_package_names:
        if dry_run:
            click.echo(apparent_bad_package)
        else:
            click.echo(
                crayons.white(
                    "Uninstalling {0}…".format(repr(apparent_bad_package)),
                    bold=True,
                )
            )
            # Uninstall the package.
            c = delegator.run(
                "{0} uninstall {1} -y".format(which("pip"), apparent_bad_package)
            )
            if c.return_code != 0:
                failure = True
    sys.exit(int(failure))


# Traceback (IndexError)
craig@amogato2:/tmp
$ pipenv clean
Creating a virtualenv for this project…
Using /usr/local/bin/python3.6m (3.6.4) to create virtualenv…
⠋Running virtualenv with interpreter /usr/local/bin/python3.6m
Using base prefix '/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/craig/.virtualenvs/tmp-agwWamBd/bin/python3.6
Also creating executable in /Users/craig/.virtualenvs/tmp-agwWamBd/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /Users/craig/.virtualenvs/tmp-agwWamBd
Traceback (most recent call last):
File "/usr/local/Cellar/pipenv/11.7.1/libexec/bin/pipenv", line 11, in <module>
load_entry_point('pipenv==11.7.1', 'console_scripts', 'pipenv')()
File "/usr/local/Cellar/pipenv/11.7.1/libexec/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/Cellar/pipenv/11.7.1/libexec/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/Cellar/pipenv/11.7.1/libexec/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/Cellar/pipenv/11.7.1/libexec/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/Cellar/pipenv/11.7.1/libexec/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/Cellar/pipenv/11.7.1/libexec/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/Cellar/pipenv/11.7.1/libexec/lib/python3.6/site-packages/pipenv/cli.py", line 459, in clean
ctx=ctx, three=three, python=python, dry_run=dry_run, verbose=verbose
File "/usr/local/Cellar/pipenv/11.7.1/libexec/lib/python3.6/site-packages/pipenv/core.py", line 2451, in do_clean
r = get_requirement(installed)
File "/usr/local/Cellar/pipenv/11.7.1/libexec/lib/python3.6/site-packages/pipenv/utils.py", line 128, in get_requirement
req = [r for r in requirements.parse(dep)][0]
IndexError: list index out of range

# Fixed code
def do_clean(ctx, three=None, python=None, dry_run=False, bare=False, verbose=False):
    # Ensure that virtualenv is available.
    ensure_project(three=three, python=python, validate=False)
    ensure_lockfile()
    installed_packages = filter(
        None, delegator.run("{0} freeze".format(which("pip"))).out.strip().split("\n")
    )
    installed_package_names = []
    for installed in installed_packages:
        r = get_requirement(installed)
        # Ignore editable installations.
        if not r.editable:
            installed_package_names.append(r.name.lower())
        else:
            if verbose:
                click.echo("Ignoring {0}.".format(repr(r.name)), err=True)
    # Remove known "bad packages" from the list.
    for bad_package in BAD_PACKAGES:
        if bad_package in installed_package_names:
            if verbose:
                click.echo("Ignoring {0}.".format(repr(bad_package)), err=True)
            del installed_package_names[installed_package_names.index(bad_package)]
    # Intelligently detect if --dev should be used or not.
    develop = [k.lower() for k in project.lockfile_content["develop"].keys()]
    default = [k.lower() for k in project.lockfile_content["default"].keys()]
    for used_package in set(develop + default):
        if used_package in installed_package_names:
            del installed_package_names[installed_package_names.index(used_package)]
    failure = False
    for apparent_bad_package in installed_package_names:
        if dry_run:
            click.echo(apparent_bad_package)
        else:
            click.echo(
                crayons.white(
                    "Uninstalling {0}…".format(repr(apparent_bad_package)),
                    bold=True,
                )
            )
            # Uninstall the package.
            c = delegator.run(
                "{0} uninstall {1} -y".format(which("pip"), apparent_bad_package)
            )
            if c.return_code != 0:
                failure = True
    sys.exit(int(failure))