On 20/06/2019 11:44, mhysnm1...@gmail.com wrote: > I have a list of strings that I want to break them into separate words, and > a combination of words then store them into a list. Example below of a > string:
> "Hello Python team". > The data structure: > [ ['Hello'], > ['Hello', 'Python'], > ['Hello', 'Python', 'team'], > ]'Python'], > ]'Python', 'team'], > ['team'] ] > > > > I want to know if there is a better method in doing this without the > requirement of a module. Modules are there to be used... Here is one with itertools from the standard library that gets close: input = "hello Python team".split() result = [] for n in range(len(input): result += [item for item in it.combinations(input,n+1)] If you really want to do it from scratch then Google combinations algorithm, or look on wikipedia. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor