#๐Ÿ”’ Just a small question about how short people's solutions are

60 messages ยท Page 1 of 1 (latest)

pale relic
#

Hey so I'm solving on codewars, and it really annoyes me how I right 14 lines of code and I see others just type down 1 line of code
I mean , good for them, but is it correct to do such a thing? am I not a good programmer because I can't solve solutions with 1 line

I mean last one I wrote so much code that i got a timeout error ( but I'm not sure if someone have solved it using 1 line or not, cuz I didn't get access to the solutions)

velvet mothBOT
#

@pale relic

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

modest mirage
#

Amount of lines in code is not a great way to decide "correctness". For some problems, smaller solutions more explicit. But others its the opposite.

I wouldn't really worry about that stuff unless you really want to, most of those solutions are going to be using esoteric things or code golfing techniques

pale relic
white field
waxen oracle
#

Excessively large solutions can suggest an unfamiliarity with tools of the language and well-known algorithms, but a large solution isn't itself a problem. The readability and performance of the solution are more important.

pale relic
white field
pale relic
#

thanks so much, I really appreciate your help guys

tender warren
#

being able to make one line solutions is a testament to ones familiarity but its not something you should actually try to emulate for practicality

white field
tender warren
white field
#

linebreaks?

pale relic
tender warren
#

codegolf doesnt use type hinting

#

or ternary statements

#

or isinstance

white field
pale relic
white field
tender warren
white field
#

type hints are (mainly) just for stylization, readability
Another important aspect imo is the auto-suggestions/auto-complete. If you do:

def f(var: str):
    ...
```then when you use `var` inside the function your IDE immediately knows (assuming you're using an IDE ofc) that the `str` functions are available on it, but if you don't put that, then it can't know what type it'll be
pale relic
tender warren
white field
pale relic
tender warren
#

no

pale relic
#

oh

tender warren
#

typehints have no "functional" use

#

so it all looks the same once its compiled into bytecode

#

typehint or no

white field
tender warren
#

was bouta comment on that extra space lol

#

beat me to it

white field
#

However, I don't think there's any more left to squeeze

tender warren
#

can turn the code into a string, encode it with utf 16 and then exec that with str.decode

pale relic
white field
#

We ufortunately also can't just check if the type is an iterable and flatten based on that, because stuff like strings are also iterable, and we don't want that flatten(["abc", 3]) produces ['a', 'b', 'c', 3]

white field
#

Probably not, considering you also need the import

tender warren
#

im pretty sure for like 52 chars and over it does

#

you dont need import anything

pale relic
white field
tender warren
tender warren
#

and you want just a single list but with everything in it

#

[[1,2], [3,4]] -> [1, 2, 3, 4]

#

this is flattening

pale relic
#

ohhhh

#

this is actually handy

tender warren
#

yeah but dont do it like this lol

pale relic
#

lol, don't worry I'll search an easy way to do it (if I had to do it someday)

white field
#

Yeah, this one's just a fun thing for us to play around with, nothing actually serious

velvet mothBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.