Because for char in s, we are iterating over each character in the string s, and for each character c, we are multiplying it by 2 (c * 2) to create a new string with the character repeated twice. The join() method is then used to concatenate all the doubled characters into a single string.
see the comments below. this solution was written in Pyrthon 2. Python 3 changed the round() function for halfway cases: it used to be half away from zero (0.5 --> 1, 1.5 --> 2), now it's half towards the nearest even integer (the so-called "banker's rounding"): (0.5 --> 0, 1.5 --> 2)
It's not dissimilar to a 'for' loop with a list. Think of it as 'for [any item] in [what I'm telling you to look at]'.
In this case we're telling the program to look at a string, so the 'any item' is just 'any/each individual letter'. 'C' is simply a placeholder for that.
I appreciate this is checks watch 11 months late, but I hope it helps if you ever return here!
Because for char in s, we are iterating over each character in the string s, and for each character c, we are multiplying it by 2 (c * 2) to create a new string with the character repeated twice. The join() method is then used to concatenate all the doubled characters into a single string.
see the comments below. this solution was written in Pyrthon 2. Python 3 changed the
round()
function for halfway cases: it used to be half away from zero (0.5 --> 1
,1.5 --> 2
), now it's half towards the nearest even integer (the so-called "banker's rounding"): (0.5 --> 0
,1.5 --> 2
)How come when I did it it was incorrect????
Which verion did you do?
Really good to know that this exist.
not efficient
Nice!
This comment is hidden because it contains spoiler information about the solution
Less lines of code = better
duh
This is really quite novel. Nice!
It's not dissimilar to a 'for' loop with a list. Think of it as 'for [any item] in [what I'm telling you to look at]'.
In this case we're telling the program to look at a string, so the 'any item' is just 'any/each individual letter'. 'C' is simply a placeholder for that.
I appreciate this is checks watch 11 months late, but I hope it helps if you ever return here!
how did such a suboptimal solution get to the top?
This comment is hidden because it contains spoiler information about the solution
That's brilliant! I would have never thought of that myself!
dope!, this was my first thought but it felt too easy and I doubted mysefl.
xor solution is n. Most efficient
Loading more items...