<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to solve this python question? I can't figure out at all...this one is stubbo in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-solve-this-python-question-i-can-t-figure/m-p/680405#M52726</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You could use this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def average_word_length(text):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' Return the average length of all words in text. Do not
&amp;nbsp;&amp;nbsp;&amp;nbsp; include surrounding punctuation in words.
&amp;nbsp;&amp;nbsp;&amp;nbsp; text is a non-empty list of strings each ending in \n.
&amp;nbsp;&amp;nbsp;&amp;nbsp; At least one line in text contains a word.'''

&amp;nbsp;&amp;nbsp;&amp;nbsp; words = text.split()
&amp;nbsp;&amp;nbsp;&amp;nbsp; for word in words:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; average=sum(float(len(word)) for word in words)/float(len(words))
&amp;nbsp;&amp;nbsp;&amp;nbsp; return average&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sounds a lot like this post:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/103785-Hey-I-was-wondering-about-this-function-problem-for-a-while" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/103785-Hey-I-was-wondering-about-this-function-problem-for-a-while&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;... on comparing signatures ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:39:19 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2021-12-12T04:39:19Z</dc:date>
    <item>
      <title>How to solve this python question? I can't figure out at all...this one is stubborn</title>
      <link>https://community.esri.com/t5/python-questions/how-to-solve-this-python-question-i-can-t-figure/m-p/680402#M52723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;def average_word_length(text):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """ (list of str) -&amp;gt; float&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Precondition: text is non-empty. Each str in text ends with \n and at&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; least one str in text contains more than just \n.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return the average length of all words in text. Surrounding punctuation&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; is not counted as part of the words. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt;&amp;gt; text = ['James Fennimore Cooper\n', 'Peter, Paul and Mary\n']&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt;&amp;gt; average_word_length(text)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5.142857142857143 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Feb 2014 23:09:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-solve-this-python-question-i-can-t-figure/m-p/680402#M52723</guid>
      <dc:creator>PeterPete</dc:creator>
      <dc:date>2014-02-28T23:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this python question? I can't figure out at all...this one is stubbo</title>
      <link>https://community.esri.com/t5/python-questions/how-to-solve-this-python-question-i-can-t-figure/m-p/680403#M52724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;def average_word_length(text):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """ (list of str) -&amp;gt; float&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Precondition: text is non-empty. Each str in text ends with \n and at&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; least one str in text contains more than just \n.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return the average length of all words in text. Surrounding punctuation&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; is not counted as part of the words. &lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt;&amp;gt; text = ['James Fennimore Cooper\n', 'Peter, Paul and Mary\n']&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt;&amp;gt; average_word_length(text)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5.142857142857143 &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I would approach it by first removing the '\n' from the string and removing the punctuation from the string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After that, split the string by looking for the spaces in it, which should provide you with a tuple of each word in the string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Then, loop each word getting its length and calculate an average from each word.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a guess at the code below. I haven't tested this so who knows if the syntax is correct...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Also look here: &lt;/SPAN&gt;&lt;A href="http://stackoverflow.com/questions/12761510/python-how-can-i-calculate-the-average-word-length-in-a-sentence-using-the-spl" rel="nofollow noopener noreferrer" target="_blank"&gt;http://stackoverflow.com/questions/12761510/python-how-can-i-calculate-the-average-word-length-in-a-sentence-using-the-spl&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;Best of luck! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
text = ['James Fennimore Cooper\n', 'Peter, Paul and Mary\n']

for scen in text:
&amp;nbsp;&amp;nbsp;&amp;nbsp; string = scen.replace('\n','')
&amp;nbsp;&amp;nbsp;&amp;nbsp; #this would be any punctuation you want to replace
&amp;nbsp;&amp;nbsp;&amp;nbsp; string = string.replace("'","")

&amp;nbsp;&amp;nbsp;&amp;nbsp; #confirm syntax 
&amp;nbsp;&amp;nbsp;&amp;nbsp; string = string.split(' ')

&amp;nbsp;&amp;nbsp;&amp;nbsp; wordcount = len(string)
&amp;nbsp;&amp;nbsp;&amp;nbsp; wordlen = 0

&amp;nbsp;&amp;nbsp;&amp;nbsp; for word in string:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmplen = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for letter in word:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmplen += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wordlen += tmplen
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; avglen = (wordcount/wordlen)

&amp;nbsp;&amp;nbsp;&amp;nbsp; print avglen

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:39:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-solve-this-python-question-i-can-t-figure/m-p/680403#M52724</guid>
      <dc:creator>CodyScott</dc:creator>
      <dc:date>2021-12-12T04:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this python question? I can't figure out at all...this one is stubbo</title>
      <link>https://community.esri.com/t5/python-questions/how-to-solve-this-python-question-i-can-t-figure/m-p/680404#M52725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I would approach it by first removing the '\n' from the string and removing the punctuation from the string.&lt;BR /&gt;After that, split the string by looking for the spaces in it, which should provide you with a tuple of each word in the string.&lt;BR /&gt;Then, loop each word getting its length and calculate an average from each word.&lt;BR /&gt;&lt;BR /&gt;Here is a guess at the code below. I haven't tested this so who knows if the syntax is correct...&lt;BR /&gt;Also look here: &lt;A href="http://stackoverflow.com/questions/12761510/python-how-can-i-calculate-the-average-word-length-in-a-sentence-using-the-spl" rel="nofollow noopener noreferrer" target="_blank"&gt;http://stackoverflow.com/questions/12761510/python-how-can-i-calculate-the-average-word-length-in-a-sentence-using-the-spl&lt;/A&gt;&lt;BR /&gt;Best of luck! &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
text = ['James Fennimore Cooper\n', 'Peter, Paul and Mary\n']

for scen in text:
&amp;nbsp;&amp;nbsp;&amp;nbsp; string = scen.replace('\n','')
&amp;nbsp;&amp;nbsp;&amp;nbsp; #this would be any punctuation you want to replace
&amp;nbsp;&amp;nbsp;&amp;nbsp; string = string.replace("'","")

&amp;nbsp;&amp;nbsp;&amp;nbsp; #confirm syntax 
&amp;nbsp;&amp;nbsp;&amp;nbsp; string = string.split(' ')

&amp;nbsp;&amp;nbsp;&amp;nbsp; wordcount = len(string)
&amp;nbsp;&amp;nbsp;&amp;nbsp; wordlen = 0

&amp;nbsp;&amp;nbsp;&amp;nbsp; for word in string:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmplen = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for letter in word:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmplen += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wordlen += tmplen
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; avglen = (wordcount/wordlen)

&amp;nbsp;&amp;nbsp;&amp;nbsp; print avglen

&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Oh, if you had a ton of punctuation you wanted to get rid of everytime, write a function to parse the text and return the "stripped" version of your text&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:39:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-solve-this-python-question-i-can-t-figure/m-p/680404#M52725</guid>
      <dc:creator>CodyScott</dc:creator>
      <dc:date>2021-12-12T04:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to solve this python question? I can't figure out at all...this one is stubbo</title>
      <link>https://community.esri.com/t5/python-questions/how-to-solve-this-python-question-i-can-t-figure/m-p/680405#M52726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You could use this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def average_word_length(text):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ''' Return the average length of all words in text. Do not
&amp;nbsp;&amp;nbsp;&amp;nbsp; include surrounding punctuation in words.
&amp;nbsp;&amp;nbsp;&amp;nbsp; text is a non-empty list of strings each ending in \n.
&amp;nbsp;&amp;nbsp;&amp;nbsp; At least one line in text contains a word.'''

&amp;nbsp;&amp;nbsp;&amp;nbsp; words = text.split()
&amp;nbsp;&amp;nbsp;&amp;nbsp; for word in words:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; average=sum(float(len(word)) for word in words)/float(len(words))
&amp;nbsp;&amp;nbsp;&amp;nbsp; return average&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sounds a lot like this post:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/103785-Hey-I-was-wondering-about-this-function-problem-for-a-while" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/103785-Hey-I-was-wondering-about-this-function-problem-for-a-while&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;... on comparing signatures ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:39:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-solve-this-python-question-i-can-t-figure/m-p/680405#M52726</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T04:39:19Z</dc:date>
    </item>
  </channel>
</rss>

