15
Last seen 9 years ago
Member for 9 years, 11 months, 10 days
Difficulty Normal
Just out of curiosity, is there any reason to use while loops instead of for loops?
More
Nice code, I like comparing the lower-case string to the original to find capitals. I have a few suggestions though.
- The input is already a string, line 2 is not needed.
- The try/except blocks will only ever catch an IndexError if len(texte)==0. You can avoid this by using a for loop instead
More
Is there an advantage to using a try/except block instead of checking the array length?
More
If you want to be a little more concise, you can unpack the date arguments directly into the datetime function with a '*'.
datetime.datetime(*d1) == datetime.datetime(d1[0],d1[1],d1[2])
More
I hadn't realized you could alter a list with .extend() while iterating through it with a for loop, that's good to know. Thank you.
More
Very cool solution. If you wanted to be a little more concise, you don't need to pass the current total (curr) down the recursive chain and then back up, you can get away with passing the running total back up only.
For instance,
def partial(data):
if data:
return dat
More
Hello,
If you wanted, lines 15 and 16 could be rewritten as just
return False
which I find to be more clear. Up to you though :-).
It is an interesting idea to keep a running count of how many more brackets have been opened than closed as well as a stack, but I think it is not neede
More
I hadn't thought of putting an int in the list instead of the word itself, thank you for the education :-)
More
I misunderstood the task. line #3 is Unnecessary and also makes my function break on inputs such as
count_words("AB CAB",{'abc'})
More
Excellent code, and excellent explanation. Thank you for taking the time to share.
More
Nice, clear code. Just a note though, it's considered bas practice to use a built in function as a variable name (min for minutes is already used for the minimum function).
More
Very nice! If you wanted to shorten the code however,
if cmd[1] == "O":
try: somme += int(stack.pop())
except: pass
Can be:
if cmd[1] == 'O' and stack:
somme += int(stack.pop())
More