{"id":1764,"date":"2011-12-04T21:11:08","date_gmt":"2011-12-04T21:11:08","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=1764"},"modified":"2011-12-04T21:11:08","modified_gmt":"2011-12-04T21:11:08","slug":"google-python-code-string2-py","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2011\/12\/04\/google-python-code-string2-py\/","title":{"rendered":"Google python code, string2.py"},"content":{"rendered":"<p>As from the <a href=\"http:\/\/www.codingfriends.com\/index.php\/2011\/12\/04\/google-python-code\/\">previous post<\/a>, I am doing the google&#8217;s python class code and if any one comes up different solutions to the googles version or mine, please post.  So here is the string2.py solutions from me.<\/p>\n<p>Verbing, needs to check for string over 3 and then only compare the last 3 characters for &#8216;ing&#8217;<\/p>\n<pre lang=\"python\">\r\n# D. verbing\r\n# Given a string, if its length is at least 3,\r\n# add 'ing' to its end.\r\n# Unless it already ends in 'ing', in which case\r\n# add 'ly' instead.\r\n# If the string length is less than 3, leave it unchanged.\r\n# Return the resulting string.\r\ndef verbing(s):\r\n  # +++your code here+++\r\n  if len(s) < 3:\r\n     return s\r\n  elif (s[-3:] =='ing'):\r\n     return s + 'ly'\r\n  else:\r\n     return s + 'ing'\r\n<\/pre>\n<p>Not bad, find the 'not' and 'bad', if bad after not then replace.<\/p>\n<pre lang=\"python\">\r\n# E. not_bad\r\n# Given a string, find the first appearance of the\r\n# substring 'not' and 'bad'. If the 'bad' follows\r\n# the 'not', replace the whole 'not'...'bad' substring\r\n# with 'good'.\r\n# Return the resulting string.\r\n# So 'This dinner is not that bad!' yields:\r\n# This dinner is good!\r\ndef not_bad(s):\r\n  # +++your code here+++\r\n  notV = s.find('not')\r\n  badV = s.find('bad')\r\n  if (badV > notV):\r\n     return s[:notV] + 'good' + s[(badV+3):]\r\n  return s\r\n<\/pre>\n<p>Font back, here we needed the modulus function to find out the reminder of a division.<\/p>\n<pre lang=\"python\">\r\n# F. front_back\r\n# Consider dividing a string into two halves.\r\n# If the length is even, the front and back halves are the same length.\r\n# If the length is odd, we'll say that the extra char goes in the front half.\r\n# e.g. 'abcde', the front half is 'abc', the back half 'de'.\r\n# Given 2 strings, a and b, return a string of the form\r\n#  a-front + b-front + a-back + b-back\r\ndef front_back(a, b):\r\n  # +++your code here+++\r\n  aV = len(a)\/2+(len(a)%2)\r\n  bV = len(b)\/2+(len(b)%2)\r\n  return a[:aV]+b[:bV]+a[aV:]+b[bV:]\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As from the previous post, I am doing the google&#8217;s python class code and if any one comes up different solutions to the googles version or mine, please post. So here is the string2.py solutions from me. Verbing, needs to check for string over 3 and then only compare the last 3 characters for &#8216;ing&#8217; &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2011\/12\/04\/google-python-code-string2-py\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Google python code, string2.py<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[286],"tags":[388,409],"class_list":["post-1764","post","type-post","status-publish","format-standard","hentry","category-python","tag-google-code","tag-python"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1764"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1764\/revisions"}],"predecessor-version":[{"id":1765,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1764\/revisions\/1765"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}