0
What is wrong in this code coach solution of "Military Time"
I don't know why but this "lst" returns None when printed Please help https://code.sololearn.com/c5SZM29vXodo/?ref=app
15 Respuestas
+ 3
Alright ...
t = tinput.split(" ")
Creates a `list` of string
lst = t[0].split(':').append(f)
t[0].split(':') splits first element in <t> and creates another `list`. This temporary `list` is the calling `list` - it calls its append() method to add <f> in as new item.
append() method added <f> into the temporary `list` but append() doesn't return a new `list` with the new item.
Since append() doesn't return anything, a `None` object is assigned as data for variable <lst>.
If append() return a new `list` with the new item in, then that new `list` can be said as the modified `list`. But no, append() returns nothing ...
+ 4
Arin the .append(f) is not doing anything useful. Remove it.
If I enter 12:30 AM it wrongly prints 12:30. It should print 00:30.
+ 3
append() method only appends something to the calling `list`, the method doesn't return the modified `list`. In Python, functions/methods that doesn't explicitly return anything will, by default, returns `None`
+ 2
Arin I admit that it puzzles me, too. If you do the append on separate line, then it works (lst.append(f)). But in the final analysis it is unnecessary for this program.
+ 2
Brian ok then
Thanks for help
+ 2
Rob the task we are discussing is from Code Coach.
https://sololearn.com/coach/70/?ref=app
Please check it. Your solution gives an error when using input from the Code Coach tests.
I have a three-line solution, but I am not posting it here. Understand that Sololearn discourages posting solutions to Code Coach, as that defeats the purpose of learning by doing it yourself.
+ 2
A simplified version Arin
Check it out
Please give me upvote
https://code.sololearn.com/c0Tf803CATkS/?ref=app
+ 1
Ipang can you please shortly explain what is calling list and what is modified list?
+ 1
Ipang ok thanks for help
+ 1
Rob your code had some mistakes
I fixed it and tried to simplify it
Although i don't think doing this in this method is good, u should try to apply something better than this
https://code.sololearn.com/cVkUfeAUWFpe/?ref=app
+ 1
Arin I sent the link to you in DM.
+ 1
#just one line without import of corse..
from dateutil import parser
print(parser.parse(input()).strftime("%H:%M"))
#learn libraries if you want to do something like that..
0
Brian ok I understand my mistake now
But can u tell me why is it printing none when I do print(lst)?
It should print a list with 3 items
0
I just did it really simply. You guys all complicate it. Here is my code if you wanna check it out. And btw try to name your variables so it's easier to read for yourself and other people
https://code.sololearn.com/cJudHkq1G4ME/?ref=app
0
Brian can u send me the three line solution
I am eager to see this because i have done it in a long method