<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_pydoc_completions(modulename):
 """Get possible completions for modulename for pydoc. Returns a list of possible values to be passed to pydoc. """

    modulename = compat.ensure_not_unicode(modulename)
    modulename = modulename.rstrip(".")
    if modulename == "":
        return sorted(get_modules())
    candidates = get_completions(modulename)
    if candidates:
        return sorted(candidates)
    needle = modulename
    if "." in needle:
        modulename, part = needle.rsplit(".", 1)
        candidates = get_completions(modulename)
    else:
        candidates = get_modules()
    return sorted(candidate for candidate in candidates
                  if candidate.startswith(needle))