Friday, 23 August 2013

Python 3.3.2 - Creating a List of the Length of Words

Python 3.3.2 - Creating a List of the Length of Words

I have a string of words with punctuation, let's say for example...
string = 'Did the quick brown fox *really* jump over the fence?'
I have filtered out the punctuation, so it is now:
'Did the quick brown fox really jump over the fence'
And I have split it up into a list.
list = string.split()
Now, with list, I now need to count the length of each word into a list,
with the length of the list being the longest word. The setting out of the
list will be as follows:
lengthList = [1_letter_words, 2_letter_words, 3_letter_words, ...]
So, for string, it would be:
lengthList = [0, 0, 4, 2, 3, 1]
Unfortunately, I am having trouble doing this. Can anyone please provide
any assistance?
Thank you.

No comments:

Post a Comment