I mean… I understood it, and I fucking hate Python. It’s pretty straight forward code, and I worry for people here who claim they’re programmers who also can’t follow it.
I think there's a big difference between "I understood what it's roughly trying to do" and "It is good".
So while glancing at lexed = [list comprehension that does splits on semi-colon terminated strings it reads from a file object] should tell most programmers what we're trying to do (tokenize some input), this code looks like a quick hacky attempt to parse something that works well enough on a handful of sample inputs but will soon start behaving oddly when the rubber meets the road.
It's entirely possible it does exactly what it needs to but some things that stand out to me:
.lstrip() when they probably wanted to do .strip() - to remove leading and trailing spaces
the j != '' filter paired with .split(" ") suggests they didn't realise you could just call .split()
replacing tabs with empty strings, probably a workaround because they wrote the code, then started encountering tabs in some input and had already added that j != '' filter
Impossible to properly judge a single line without context, but encountering this code in a PR would cause a raised eyebrow for most semi-experienced Python devs.
Not sure I ever claimed it was good, it’s just not the horror some people seem to think it is. I agree it could certainly be improved, particularly to handle potential edge cases (tab should at the very least be replaced with space), but depending on what it’s actually being used for, it might be perfectly adequate and match the format produced by some other code.
Yeah without context we can't know, but I've had to work with a lot of code written by junior Python devs that does relatively simple parsing. It tends to look like the snippet above after one or two attempts to "fix" it, then starts to grow legs and then they discover regexes...
But you're right it's not the most horrific thing in the world, it just smacks of either inexperience or "this is good enough for the one-off task I'm using it for"
I am making it a point of pride to go through this entire stupid AI bubble without writing a single line of code with those shitty chatbots, which are the bane of my existence.
this code looks like a quick hacky attempt to parse something that works well enough on a handful of sample inputs but will soon start behaving oddly when the rubber meets the road.
So you're saying you wrote this text yourself? If so, I apologize for my accusation, it just reads like classic Claude output with the step by step analysis and metaphors used.
That's pretty clean for doing that in python. It's just hard to wrap your sensibilities around that particular feature of the language but once you do you see opportunities to use it that save you a dozen lines or more. Assign it to a lambda and you got yourself a function baby!
Oh look it's Python one liners, I like those. Find attached a sample of my creations :P
out2in = {k: ([("#" + x["tag"] if x.get("tag") else x["item"]) if x.class.name == "dict" else [("#" + y["tag"] if y.get("tag") else y["item"]) for y in x] for x in v]) for (k, v) in {(y["result"]["item"] if y["result"].class.name == "dict" else y["result"]): ((y["ingredients"] if y["ingredients"].class.name == "list" else ([y["ingredients"]]) if y.get("ingredients") else y["ingredient"]) if y.get("ingredients") else [z for z in y["key"].values()]) for y in filter(lambda x: x.get("result") and (x.get("ingredients") or x.get("key")), [json.load(open(x, "rt")) for x in Path("recipes").glob("*.json")])}.items()}
sectors = list([(sector, system_ids) for (sector, system_ids) in [(sector.name, set(range(sector.max_id)) ^ {int(system["name"].split("AA-A h")[-1]) for system in json.loads(globals()["res"].text)}) for sector in tqdm(sorted([globals()["curr"] for row in csv.DictReader(input) if sum([row[k] == None for k in ["Sector", "AA-A_h systems", "Highest Number", "Sector Total Systems", "Avg X", "Avg Y", "Avg Z", "Min X", "Min Y", "Min Z", "Max X", "Max Y", "Max Z", "MapSector X", "MapSector Y"]]) == 0 if setattr(sys.modules[__name__], "curr", Sector(row["Sector"], int(row["AA-A_h systems"]), int(row["Highest Number"]), Point3D(float(row["Avg X"]), float(row["Avg Y"]), float(row["Avg Z"])), Point3D(float(row["Min X"]), float(row["Min Y"]), float(row["Min Z"])), Point3D(float(row["Max X"]), float(row["Max Y"]), float(row["Max Z"])), Point2D(int(row["MapSector X"]), int(row["MapSector Y"])))) == None if (globals()["curr"].max_id + 1 - globals()["curr"].discovered) > 0], key = lambda x: x.avg.distance_to(CURRENT_COORDS)), desc = "Searching sectors for unexplored systems", unit = " sectors") if setattr(sys.modules[__name__], "res", requests.post(API_GET_SYSTEMS, None, {"systemName": sector.name + " AA-A h"})) == None if (sleep(int(globals()["res"].headers["x-rate-limit-reset"])) if (int(globals()["res"].headers["x-rate-limit-remaining"]) == 0) else None) == None]])
11
u/v_maria Sep 16 '26
ah yes functional programming
34
u/Wrestler7777777 Sep 16 '26
Man, sometimes line breaks go a really long way.
4
u/tvardero Sep 16 '26
One-line enjoyers, oh yeah
2
u/gfivksiausuwjtjtnv Sep 16 '26
Just read it inside out
2
u/abigail3141 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Sep 21 '26
Oh look it's Python one liners, I like those. Find attached a sample of my creations :P
The latter in image form if preferred: https://www.reddit.com/r/programminghorror/comments/1tcytxy/it_is_evolving/
1
u/Kadabrium Sep 21 '26
At least you dont need to indent
1
u/NullOfSpace Sep 22 '26
I’m just upset they’re collecting the inner one into a list and not using a generator expression
1
u/0xt0bi03 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Sep 22 '26
just python things
1
u/AnArmoredPony Sep 22 '26
a csv parser ig
1
u/M4elstr0m__ Sep 25 '26
I used to create such lines just to bother collegues trying to understand my code..
1
u/thelurkmasterr Sep 30 '26
This is the type of thing that makes sense while you're writing it, but you better not go back and change it
1
u/Tack1234 Sep 16 '26
Should I be scared that as someone writing my own assembler for fun I see no issue with this?
-2
u/asmanel Sep 16 '26
Visibly a vibe coding peoduct.
0
u/[deleted] Sep 16 '26
[deleted] — view deleted comment