# Given a string 'str', this counts all substrings with length 2 and print them def countsubstrings(str): dict = {} # dictionary: key => substring , value => its frequency for i in range(len(str)): substr = str[i:i+2] # substring with length 2 if len(substr) < 2: continue # substr must have at least two length # check if 'substr' is in count return(dict) if __name__ == '__main__': import sys str = sys.argv[1] # print str # for debug dict = countsubstrings(str) print dict # for debug # 'sort' is not yet # this will be a subject of 6/18 # print all substrings