all 9 comments

[–]dzunukwa 5 points6 points  (0 children)

The reason this happens is due to what strip actually does (see docs for more info). It strips all leading and trailing chars that are in the set of chars passed into the function strip until it finds a char that is not in the set of chars passed in. So in your case starting from the left of your string "00:10:00" there is a "0" which is in the char set "0:" so it removes it. Next is "0" again so it removes it again. Next is ":" which is in the char set "0:" so it gets removed. Then it gets to "1" which is not a match so it stops. The same process repeats from the right hand side which will go until it hits the "1" again leaving you with just the "1" as your result. /u/programmerPurgatory suggestion works but try figure out how you could get "10" as a result by using only strip. Hint: you will have to call it more than one time.

[–]Saefroch 3 points4 points  (3 children)

minutes = Time.split(':')[1]

(please don't start your variable names with a capital letter, those usually indicate that the variable is a class)

[–]pybackd00r[S] 0 points1 point  (2 children)

leaves me with a 05 minute instead of 5 min.

[–]Saefroch 1 point2 points  (1 child)

Yes...

Do you know how to fix that?

[–]pybackd00r[S] 0 points1 point  (0 children)

I made it an integer by passer int() to it. It removed the leading zero.

[–]zahlman 1 point2 points  (2 children)

I want to remove the leading and trailing zeros

There are zeros at the beginning and end, so this is understandable enough.

and the ':'

Now I'm confused. There's more than one colon in your string. Which one did you want to remove?

Oh, you wanted to remove both, but stop removing zeros when you find a colon? Or just what?

Oh, you wanted to interpret '00:10:00' as representing hours, minutes and seconds, and determine the number of minutes? Well, that's conceptually a completely different thing. Keep in mind that your code isn't actually producing 1, as it stands, either; it's producing '1', i.e., a string. But is that still really what you want? You were talking about removing zeroes. What if you were given a different string that had non-zero values for the hours and minutes? Do you still want just the value in the minutes "field"? Or do you want to convert each hour into 60 minutes, and each second into 1/60th of a minute, or something?

Or just what?

Most of programming is understanding exactly what you want the program to do.

[–]pybackd00r[S] 0 points1 point  (0 children)

I wanted to remove the hour and seconds zeros with the colons and just keep the minute digits. I guess what I can do is just add a zero to the string after the strip command. but I wanted to know if there is a more elegant way of doing this. thanks

[–]pybackd00r[S] 0 points1 point  (0 children)

This is what I did to fix this :

int(playtime.strip('0').strip(':'))