Code navigation not available for this commit Please reload CAPTCHA.

This site uses Akismet to reduce spam.
Have a look at the subsequent if-statements, and think about how they relate to the variable i being iterated in the for-loop.

Pretty self explanatory, the solutions I came up with when I did the problem We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. Rather, my question centers around the usefulness of using Python’s built-in list methods, as opposed to writing something more ‘verbose’.

We use essential cookies to perform essential website functions, e.g.

if ‘xyz’ in str:

programmatic thinking, which is why Nick Parlante didn’t include the count() method in his overview of strings in Python. Learn more. Contribute to faayam/coding-bat-solutions development by creating an account on GitHub. You signed in with another tab or window.

Spammer prevention; the answer is an integer: Time limit is exhausted.

Hmm, well I replied to your Python solutions–not the Java ones.

return False, Easier way for count_hi() return str.count(‘xyz’) > str.count(‘.xyz’). return False. But for the example count_hi and cat dog, I would appreciate some help! For ‘cat_dog’, would you criticize this solution: for xyz:

I know it’s an old topic, but last exercise could be shortened to that: ); Learn more. for i in range(len(str)): #I didn’t use “len(str)-1” here. Hey guys, I sometimes understand why this is the case, but in other situations..I don’t.

def xyz_there(str):  + 

You’re using an in-built method, which defeats the purpose of this exercise. sets. return True they're used to log you in. That works, but it won’t teach you the skills CodingBat is intended to teach.

My solutions to codingbat.com python problems.

}. However, I noticed that you used len(str) -1. You can always update your selection by clicking Cookie Preferences at the bottom of the page. Please explain. Pretty self explanatory, the solutions I came up with when I did the problem sets. if ( notice ) def cat_dog(str): count = 0

display: none !important;

# except when “xyz” is the beginning pf str. they're used to gather information about the pages you visit and how many clicks you need to accomplish a task. Practice Link: [ CodingBat Python ] (http://codingbat.com/python). return False, This is a better solution than the one you gave for `xyz_there`. My solutions to codingbat.com python problems. If nothing happens, download GitHub Desktop and try again.

Required fields are marked *, Spammer prevention; the answer is an integer: * seven You’re not supposed to use the method ‘replace’. August 2020 (1) May 2020 (1) November 2019 (1) August 2019 (1) July 2019 (1) March 2019 (1) February 2019 (2) January 2019 (2) Yes, the String class in Python does have a method named count. })(120000); String-2; Azgar on Coding Bat: Python. When it comes to seeing if a string starts with a certain sequence of letters, I understand why it is done. function() { You can always update your selection by clicking Cookie Preferences at the bottom of the page.

# Affix character ‘a’ in front of str

# So my thinking is, if I add another valid character in front so that this Is it because the last index is omitted in the range(len), so we only need to subtract 1 to get to -2? No definitions found in this file. def xyz_there(str):

Code definitions.

If nothing happens, download GitHub Desktop and try again. setTimeout( if str.count('cat') == str.count('dog'): return True Contribute to mirandaio/codingbat development by creating an account on GitHub. Very nice – but you don’t need to test for .xyz before replacing.

String-2; John doe on Coding Bat: Python. For more information, see our Privacy Statement. # leading “xyz” is counted, then I avoid writing another if statement, for i in range(len(str) – 3):

String-2; Gregor Ulm on Coding Bat: Python.

Work fast with our official CLI. CodingBat Python Solutions. why is it that you do

However, assuming such a method exists, and does what you intend it to do, you could simply write “return str.count(‘cat’) == str.count(‘dog’)”.

New Publication: S-RASTER: Contraction Clustering for Evolving Data Streams, New Paper Published: “Active-Code Replacement in the OODIDA Data Analytics Platform”, New Preprint: S-RASTER: Contraction Clustering for Evolving Data Streams, Upcoming Poster Presentation at Euro-Par 2019, New Preprint: Contraction Clustering (RASTER): A Very Fast Big Data Algorithm for Sequential and Parallel Density-Based Clustering in Linear Time, Constant Memory, and a Single Pass.

We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. If nothing happens, download the GitHub extension for Visual Studio and try again.

There are probably better solutions, comments are welcome. After perusing your blog articles it seems that you have opinions about most things computer science-related, so I thought I would ask what you thought. Work fast with our official CLI. timeout

.hide-if-no-js {

However, the point of the Coding Bat exercises is to teach you basic programming skills, i.e. Your email address will not be published. Learn more, We use analytics cookies to understand how you use our websites so we can make them better, e.g. for i in range(len(str) – 2): or (-1) in the other case?

If nothing happens, download the GitHub extension for Visual Studio and try again.

Cheating. Nobody likes a cheater and you will eventually get caught, so use this for

We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products.

You signed in with another tab or window. Your email address will not be published. download the GitHub extension for Visual Studio.
That’s because strings are zero-indexed in Java. All solutions were successfully tested on 18 April 2013. For more information, see our Privacy Statement.

For cat_dog, why do we iterate till len(str) – 2 and not len(str) – 1.

(function( timeout ) { Can you please explain in case value of both xyz and .xyz is 1, as in string “.xyzxyz” then why does it still return True? Solutions to CodingBat problems.

Can you please explain why the -1 would matter? return str.count(‘hi’). GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. if ‘.xyz’ in str: if str[i:i+2] == ‘hi’:

str = “a” + str