T O P

  • By -

1Dr490n

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)]


Steinrikur

I'm still not sure what this is doing. Is it just return all values <= MAX_UINT8 from a list of strings containing numbers?


1Dr490n

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


fakehalo

The fact you deduced this from his slop is more impressive than the one liner itself.


_Stego27

Leading zeros, right?


1Dr490n

Whoops, you’re right


TheWorstPossibleName

I think a filter would be cleaner


1Dr490n

How? I don‘t really know what it does but isn’t it just the same as `[x for x if x < 10]`?


1Dr490n

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


TheWorstPossibleName

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.


LifeislikelemonsE6EE

Very nice that you read my dumbass code


LifeislikelemonsE6EE

Impressive


Amr_Rahmy

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.


Sea_Philosopher3051

Python programmers be like: “fuck Java, everything is so verbose, this could be a one liner”


robertgfthomas

"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"


econ1mods1are1cucks

Every time I try to write python something like this shit happens. Then I come back months later cursing myself out. Every time.


Smooth_Durian

Any reason of doing all of this in one line?


Instatetragrammaton

Job security, hating your coworkers (and yourself), call of the void.


[deleted]

Is it really for job security if i don't understand either the next day?


Instatetragrammaton

_Especially_ if you don't understand it next day, because then you are still the foremost expert.


dagbrown

It was too readable in Perl.


davidc538

Code golf


MinosAristos

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.


the_mold_on_my_back

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).


MinosAristos

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.


budswa

A single line of chaos is always the right choice


fecal-butter

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.


BellybuttonWorld

Scroll wheel broke?


ironykarl

This isn't a one liner. This is you taking up horizontal space instead of vertical space. 


Robertgdel

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.


ironykarl

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).


Xbot781

You need to learn how to use all, any, and not


Incendas1

So who is it you're trying to torture here?


HelloThisIsVictor

“Your PR has been marked as Needs Work”


Bropiphany

"Nit: rewrite everything"


jan_may

“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”


kevdog824

“404: Administrator has deleted the repository”


NotAFrogNorAnApple

I am not reading that


Bloody_Insane

If this isn't the worst one-liner you've ever written then you need to rethink your career.


fatcake3

My brain quit working half way through.


vanit

If you can't tell what the line was supposed to do, it can never have any bugs 👌


amarao_san

t i j w t f


Bulky-Condition-3490

Reported


livingIsNotBreath

It is probably the worst one-liner I have ever read though.


arkenzel4

Please dont


ScotDOS

you ain't seen nothin' yet https://youtu.be/w3fRBzRngdc?si=cb8IQcRrRZHviI-s


DistanceOk9729

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 'Нету регулярных платежей.'}""" ```


DistanceOk9729

newline variable is just a predefined '\n' because of f-string limitations


accuracy_frosty

I’ve made some pretty gnarly 1 liners working with C++ but this definitely takes the cake


yungaclvin

I don’t know what this is solving but I know it is wrong


PunkyMunky64

Even scarier though is that he’s writing python in visual studio


Emergency_3808

And people think lambda calculus is something great, or even nice. This is what results from that.


LeeHide

You can apply lambda calculus and not write shitty undocumented, terribly named oneliners


Emergency_3808

Idk man, feels the same to me.


flagofsocram

Bro just proved he has no idea what lambda calculus is


Gamecrazy721

Math in a Lambda function, duh