Thanks, so much to learn.

-----Original Message-----
From: Tutor <[email protected]> On Behalf Of
Alan Gauld via Tutor
Sent: Friday, 21 June 2019 2:26 AM
To: [email protected]
Subject: Re: [Tutor] word printing issue

On 20/06/2019 11:44, [email protected] 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  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to