Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interview task
#3
In addition to stullis's comments/recommendations:
  • There are no doc-strings. for example at the moment we cannot fully understand what your class and methods are expected to do.
  • At the same time using inline comments in the main program for obvious things
  • Using single-letter variable/attribute names
  • not using with context manager when open files
  • using if/else, instead of try/except in the main program when calling respective method - better to ask for forgiveness than for permission.
  • related to previous bullet - raising general Exception, when the actual AttributeError would do
  • The way you do it it doesn't make sense to use class. If it was requirement I guess they expected to pass sequence l1 and n at instantiation. This way you would not assign self.l1 and self.n in each method, but only once in __init__().
  • Also, I think it's better that the two methods return value, not print (unless it was specifically requested)
  • magic numbers - e.g. where this 4 on line 11 comes from? Probably it will be clear if we know the actual assignment, but still it's not clear what you do
  • I am almost certain that your code can be improved even further if the full task is clear. e.g. why using dict when list would do? You don't make use of the dict

This is non-exhaustive list, just some random thoughts while looking at your code. Please, don't take offense.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Interview task - by khazi - Feb-03-2019, 04:02 PM
RE: Interview task - by stullis - Feb-03-2019, 06:11 PM
RE: Interview task - by buran - Feb-03-2019, 07:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  count certain task in task manager[solved] kucingkembar 2 1,083 Aug-29-2022, 05:57 PM
Last Post: kucingkembar
  Schedule a task and render/ use the result of the task in any given time klllmmm 2 2,033 May-04-2021, 10:17 AM
Last Post: klllmmm
  How to create a task/import a task(task scheduler) using python Tyrel 7 3,627 Feb-11-2021, 11:45 AM
Last Post: Tyrel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020