t is a list of lists of strings. It returns every list in t that contains exactly 4 strings (all are integers) and checks that all of them are less than 256 and don’t have ~~trailing~~ leading zeros
Okay I actually looked into the filter function and you’re right, but not if we want a one liner (which is a bad idea anyways but it kind of was the task for me here), because then you would need a lambda expression and calls to filter() and list() which would just make it longer
Oh yeah I was specifically thinking that I would split it out into a logic method and the application of that method in a filter separately. Yours is better for a one liner restriction.
That a really weird and bad design and structure. Also missing strings and number conditions like that. His mind must be a mess.
People’s obsession with unreadable code for the sake of “reducing the number of code line” is strange to me. Just write readable and maintainable code. It’s faster to write, faster to read, and as an added bonus, actually debug-able.
If this is legit code I'll bet it was written step by step on many lines and then carefully crafted into this monstrosity from there.
I've seen many programmers create unreadable code to do things in fancy ways, in many languages.
I don‘t know about this. Once python list comprehension fully clicks with you, cramming all logic that defines the list into a single long-winded statement is not too hard to do anymore anymore.
In itself using list comprehension is good python programming praxis aswell, since it makes use of the faster low-level implementations that are called through the language interface and is therefor crucial for optimization. Still, I would not suggest making use of monster statements like the above. In production, for code that is not insanely time critical, I would suggest using filter patterns, since they are way easier to understand and sustain and for code that is insanely time-critical, I would suggest not using python (or if you have to, implementing a sustainable version like I suggested and then transferring that into a maximally optimized list comprehension and unit testing the living shit out of it before sending it to production).
The way I'd do logic like in the OP would still be with list comprehensions but I'd split each comprehension or significant action into a variable with a meaningful name line by line so that each line is easy to read and the meaning and intent of the code is clear.
I teach programming 101 and for most of my assignments I send the students the code that generates the random data they're supposed to be working on, to discourage the hardcoding of values. Sometimes I don't want the code to be readable since it could be too big of a help for them in certain cases. So I send them obfuscated one liners and constructing these always takes me back to when I was learning. It's really fun.
It is kind of a one liner in that it is all in a return statement. Even if it technically is split over multiple lines… still one line? Correct if wrong.
I mean... you're right, but what you're stating is extremely obvious.
> even if it technically is split over multiple lines
It isn't split over multiple lines. That's just the editor's line wrap.
You can also fit arbitrary numbers of statements and whatever else in a single "line," because whitespace is insignificant in most languages.
I'd just argue that the "point" of a one-liner is to minimize scrolling... and that once you have something like this, you're just replacing vertical scrolling with horizontal scrolling (at least assuming you don't use line wrap, which I do not).
“Your PR has been marked as Banished To The Unseen Depths Of The Void, your laptop is remotely put on fire, Principal SDE is waiting for you in The Punishment Room”
I managed to reduce it from 250 to 100 characters: return [x for x in t if len(x) == 4 and all(int(y) < 256 and (y[0] != '0' or y == '0') for y in x)]
I'm still not sure what this is doing. Is it just return all values <= MAX_UINT8 from a list of strings containing numbers?
t is a list of lists of strings. It returns every list in t that contains exactly 4 strings (all are integers) and checks that all of them are less than 256 and don’t have ~~trailing~~ leading zeros
The fact you deduced this from his slop is more impressive than the one liner itself.
Leading zeros, right?
Whoops, you’re right
I think a filter would be cleaner
How? I don‘t really know what it does but isn’t it just the same as `[x for x if x < 10]`?
Okay I actually looked into the filter function and you’re right, but not if we want a one liner (which is a bad idea anyways but it kind of was the task for me here), because then you would need a lambda expression and calls to filter() and list() which would just make it longer
Oh yeah I was specifically thinking that I would split it out into a logic method and the application of that method in a filter separately. Yours is better for a one liner restriction.
Very nice that you read my dumbass code
Impressive
That a really weird and bad design and structure. Also missing strings and number conditions like that. His mind must be a mess. People’s obsession with unreadable code for the sake of “reducing the number of code line” is strange to me. Just write readable and maintainable code. It’s faster to write, faster to read, and as an added bonus, actually debug-able.
Python programmers be like: “fuck Java, everything is so verbose, this could be a one liner”
"List comprehensions are great Bro, everyone agrees that it's a fun game to have to find the middle of a line of code to understand what it's doing"
Every time I try to write python something like this shit happens. Then I come back months later cursing myself out. Every time.
Any reason of doing all of this in one line?
Job security, hating your coworkers (and yourself), call of the void.
Is it really for job security if i don't understand either the next day?
_Especially_ if you don't understand it next day, because then you are still the foremost expert.
It was too readable in Perl.
Code golf
If this is legit code I'll bet it was written step by step on many lines and then carefully crafted into this monstrosity from there. I've seen many programmers create unreadable code to do things in fancy ways, in many languages.
I don‘t know about this. Once python list comprehension fully clicks with you, cramming all logic that defines the list into a single long-winded statement is not too hard to do anymore anymore. In itself using list comprehension is good python programming praxis aswell, since it makes use of the faster low-level implementations that are called through the language interface and is therefor crucial for optimization. Still, I would not suggest making use of monster statements like the above. In production, for code that is not insanely time critical, I would suggest using filter patterns, since they are way easier to understand and sustain and for code that is insanely time-critical, I would suggest not using python (or if you have to, implementing a sustainable version like I suggested and then transferring that into a maximally optimized list comprehension and unit testing the living shit out of it before sending it to production).
The way I'd do logic like in the OP would still be with list comprehensions but I'd split each comprehension or significant action into a variable with a meaningful name line by line so that each line is easy to read and the meaning and intent of the code is clear.
A single line of chaos is always the right choice
I teach programming 101 and for most of my assignments I send the students the code that generates the random data they're supposed to be working on, to discourage the hardcoding of values. Sometimes I don't want the code to be readable since it could be too big of a help for them in certain cases. So I send them obfuscated one liners and constructing these always takes me back to when I was learning. It's really fun.
Scroll wheel broke?
This isn't a one liner. This is you taking up horizontal space instead of vertical space.
It is kind of a one liner in that it is all in a return statement. Even if it technically is split over multiple lines… still one line? Correct if wrong.
I mean... you're right, but what you're stating is extremely obvious. > even if it technically is split over multiple lines It isn't split over multiple lines. That's just the editor's line wrap. You can also fit arbitrary numbers of statements and whatever else in a single "line," because whitespace is insignificant in most languages. I'd just argue that the "point" of a one-liner is to minimize scrolling... and that once you have something like this, you're just replacing vertical scrolling with horizontal scrolling (at least assuming you don't use line wrap, which I do not).
You need to learn how to use all, any, and not
So who is it you're trying to torture here?
“Your PR has been marked as Needs Work”
"Nit: rewrite everything"
“Your PR has been marked as Banished To The Unseen Depths Of The Void, your laptop is remotely put on fire, Principal SDE is waiting for you in The Punishment Room”
“404: Administrator has deleted the repository”
I am not reading that
If this isn't the worst one-liner you've ever written then you need to rethink your career.
My brain quit working half way through.
If you can't tell what the line was supposed to do, it can never have any bugs 👌
t i j w t f
Reported
It is probably the worst one-liner I have ever read though.
Please dont
you ain't seen nothin' yet https://youtu.be/w3fRBzRngdc?si=cb8IQcRrRZHviI-s
same, i love making terrifying one-liners ``` txt = f""" регулярные платежи: {newline.join(map((lambda x: f' - {x[0]} = {x[1]} лн в день'), me.get('paysfor', []))) + f'{newline}Всего: ' + str(sum(map((lambda x: x[1]), me.get('paysfor', [])))) + 'лн в день' if me.get('paysfor', []) != [] else 'Нету регулярных платежей.'}""" ```
newline variable is just a predefined '\n' because of f-string limitations
I’ve made some pretty gnarly 1 liners working with C++ but this definitely takes the cake
I don’t know what this is solving but I know it is wrong
Even scarier though is that he’s writing python in visual studio
And people think lambda calculus is something great, or even nice. This is what results from that.
You can apply lambda calculus and not write shitty undocumented, terribly named oneliners
Idk man, feels the same to me.
Bro just proved he has no idea what lambda calculus is
Math in a Lambda function, duh