Create all possible character combinations of any size I am trying to create all possible character combinations of a given word.  For example, “laptop” will include the following possible combinations:

l
la
lap
lapt
lapto
laptop
lp
lpa
lpat
lpato
lpatop


Here is what I have tried:

#!/usr/bin/env python
import argparse
import sys

def parse_args(argv):
    """parsing argument"""
    parser = argparse.ArgumentParser()
    parser.add_argument('-input', dest='input', type = str,
                         required = True,
                         help = "please provide string")
    args = parser.parse_args(argv)
    return args


def get_patt(patt, patt_index, new_pat):
    print new_pat
    for i in range(patt_index, len(patt), 1):
        new_pat = new_pat + patt[i]
        print new_pat
def main(args):
    f_pat = ""
    input = args.input
    for k in range(0, len(input), 1):
        for i in range(0, len(input), 1):
            f_pat =  input[i]
            for j in range(i+1, len(input), 1):
                f_pat = f_pat + input[j]
                get_patt(input, j+1, f_pat)
        input = args.input[k:] + args.input[:k]
        print "Input String", input

if __name__ == "__main__":
    args =parse_args(sys.argv[1:])
    main(args)
Improvements


Use either argparse or sys.argv because this feels just wierd,
and kind of surprised it worked at all. I'd recommend sticking with argparse
Secondly, be sure to check out the itertools module from python, because what you are looking for are basicly permutations of a word.




New code

import argparse
from itertools import permutations


def main(string):
    for idx in range(1, len(string)+1):
        print(list(''.join(p) for p in permutations(string, idx)))


def parse_args():
    """parsing argument"""
    parser = argparse.ArgumentParser()
    parser.add_argument('-input', dest='input', type = str,
                         required = True,
                         help = "please provide string")
    return parser.parse_args()


if __name__ == "__main__":
    args = parse_args()
    main(args.input)