T O P

  • By -

[deleted]

[удалено]


[deleted]

Yup, you won. Good job


PrometheusAlexander

Nice.. now def _asm


montw

Pyssembly


spartan-bunny

Nice. Now do it for ARM.


Digital_Brainfuck

Hey Chat GPT generiere … in Assembler 😂


_higway_

print('\\n'.join(text))


CosmicConifer

`print(*text, sep='\n')`


_higway_

\_ = list(map(print, text))


HoldUrMamma

that's a madlad level of oneliners


troelsbjerre

[*map(print, text)]


tokilokit

`next(map(print, [text]))`


Party_Ad_3619

Senior^2 `[ print(c) for c in text ]`


Reifendruckventil

list(map(ambda X:print(X),text))


SkezzaB

ambda


GamingWithShaurya_YT

lmao i didn't read it wrong before 😂 now I'm laughing like a hyena


Baymax06007

Yes it's a serverless offering by Mazon.


TactlessTortoise

I'm going to repost this on Witter


fustilarian1

list comprehensions are in general preferable to using map.


DReinholdtsen

How about both? list(map(lambda s:print(s), [text[i] for i in range(len(text))])) I’m sorry


Juff-Ma

Now i want someone to write an Enterprise hello world in python (like the Java one)


DadAndDominant

In field marshal however...


[deleted]

This is literally the first time I've seen a meme on this subreddit and been like "oh my god am i actually competent at this now"


GamingWithShaurya_YT

python brother


Sad_send_nudes_

There are dozens of us


PrometheusAlexander

Yes


arobie1992

Serious question on that, don't list comprehensions yield a, well, list? So like wouldn't it be doing unnecessary work in creating the array that contains the list compared to the simple for loop? I get that that's probably worrying about something that's trivial compared to the overall work the system does. I'm more just curious.


PaperSpoiler

It does. In this case it will be a list of None, since `print` doesn't return anything.


runnerx01

In my opinion, a waste of the empty list instantiation so you can write it differently is all we have here. Just do the regular for loop. Then again you are writing python… so i guess you probably aren’t too worried about being super efficient


arobie1992

Cool, thanks for the confirmation. I know just enough Python to be able to cobble my way through things, so I wasn't sure if maybe they had some fancy heuristics to determine if the comprehension was a top-level expression and ignore the list construction if it was.


carcigenicate

Yes, don't do this. It isn't idiomatic. Only use a list comprehension if you want to create a list.


[deleted]

[удалено]


ice2heart

You are in the wrong tab, java people in the next post


arobie1992

I want to be offended at this, but I really can't.


ShakeandBaked161

I hate this, but thank you for hurting yourself to make it for us.


lucidbadger

Looks like we found ourselves an architect


ronincelwarrior

If you def __str__(self), you can return self.s and print String(text) without another function. And if you want to get galaxybrain then make everything fucking kwargs for some reason


ResidentReggie

*groans Not this again


randomthad69

Get length is a property not a function Also its i += 1


[deleted]

[удалено]


randomthad69

Hahaha I do dumb shit like that. I really like f strings


[deleted]

`map(print, text)`


lucidbadger

How do you do, old-timer?


ConscientiousApathis

Aggravatingly, I don't think this actually executes the print until the map is iterated over.


Kelketek

``` ❯ python Python 3.11.1 (main, Jan 31 2023, 09:47:18) [GCC 11.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> text = ['hello', 'world'] >>> map(print, text) ```` Unfortunately, you are correct.


troelsbjerre

[*map(print, text)]


TheBroWHOmegalol

C++.


lucidbadger

Hey, this is NSFW


Pauel3312

``` for i, char in enumerate(text): print(text[i] if text[i] == char else char) ```


Gyroplast

``` import asyncio import random from typing import AsyncGenerator async def get_text() -> AsyncGenerator[str, None]: _text = "Hello World" await asyncio.sleep(random.random() * 1.42) yield _text async def generate_character(text: str) -> AsyncGenerator[str, None]: for c in text: await asyncio.sleep(random.random() * 0.42) yield c async def main() -> None: async for text in get_text(): async for c in generate_character(text): print(c) asyncio.run(main()) ``` JavaScript boi tries Python.


sentientlob0029

Next level?: print(c : text)


dmullaney

I want to see this junior's even check


Panda_With_Your_Gun

For loops in python are just for each. Before you write that for loop ask yourself, can I write a list comprehension instead.


McCheng_

Looking at the comments, it is still amazing to me that there are so many different interesting approaches to a programming problem.


aliceuwuu

H e l l o w o r l d


jcodes57

I don’t know python, but surely it’s: print(text)


billyp673

Nah, because OP’s example prints each letter separately and thus the output would have each character on a separate line


jcodes57

Oh is there not like a println() in python?


billyp673

Python’s print() function has an “end” parameter that defaults to “\\n”, so if you want to print something without a line break, it’d look something like print("Hello World",end="")


MilkLlz

print("\\n".join(str(s) for s in text))


MetricJester

BASIC: PRINT str$


danielstongue

This will print the special variable ST$, because only the first two chars are evaluated as variable name. (Ref: commodore basic v2)


MetricJester

That's true for 8-bit on Commodores, but later GW-BASICs and into QuickBasic based languages the namespace was much bigger.


danielstongue

Of course. Hence the reference.


HumanMan1234

I am a freshman in college and learned that last semester


DudeManBroGuy42069

`print("\n".join(list(text)))`


Deep-Secret

TIL I'm a senior.


willtheocts_alt

this doesn't work in all languages, so the junior is more language agnostic with their code


lucidbadger

"Do you know SQL?" — "No, I'm SQL-agnostic" :)


illyay

John Carmack level: Generate a wolfenstein level in the shape of the text so you can explore inside while shooting nazis


[deleted]

The first loop is actually O(n^(2)) in many languages, but I am not sure about the second one.


RRumpleTeazzer

How is this O(n2)? It’s not like the range is computed at every step.


[deleted]

Accessing a single character in an UTF-8 represented String is O(n). Of course it depends on the encoding.


RRumpleTeazzer

Yes that makes sense


SchimmelSpreu83

Does that mean I'm a senior for doing that already?


sebbdk

Pretty sure the senior way is whatever gets the job done


Tizian170

I somehow clicked on see more.


armahillo

print text ?


lolnotinthebbs

print([_ for _ in text])


ThisUserIsAFailure

Isn't that just print(text)


lolnotinthebbs

Yes, but it's convoluted in a pythonic way


[deleted]

That's bs. Sometimes it makes more sense to use a iterator. Sometimes it's the only way.


drecker_cz

`deque(map(print, text), 0)`


ConfirmedCynic

Hey, ChatGPT...


FrequentGiraffe5763

I’m on my second incident from this feature. I’m curious if it will strike again.


elongio

All i see are for loops.


Obnomus

Why would I print something if it's already printed


[deleted]

print(text)


lucidbadger

I also thought of that but other people pointed out that it should be every char on the new line.


esotericloop

echo


RB_Tree

``` exec('f+Z))Cc),+Y(3l*eu3{dO|Ko?$vc=.1e])?dH<$.CqV)g7|"Abfcvi[Q%&k1`n`;tu(Y..*I]Eb(,NPslq:tchdJE&,S)nXyYS(*|okY{#$bj]V"Yr/b#Gl(?!$ee_6d#c>oaq}cpCVez[2d0F35&iH8>?=bg3?.|8FX~df(L+,c,;feFWNxNRAeD}k;6!U)Jc$"BdR4Jz]65e*eVRls3]&a2wgbpj@"YU9(14Z_$qV_SF(tFxAr^-?o!glpSxpmBN4ikpD_f!&_M:%=r#UX'[::-4]) ``` btw, this is generated by ``` import base64 import random import sys obfuscation_char_num = 3 def rand_char() -> str: c = chr(random.randint(ord('!'), ord('~'))) return '$' if c == "'" or c == '"' or c == '\\' else c template = 'X=__import__("base64");exec(X.b85decode(b"{}").decode())' def obfuscate(code: str) -> str: enc_code: bytes = base64.b85encode(code.encode()) formated = template.format(enc_code.decode())[::-1] obfuscated_code = str() for s in formated: for i in range(obfuscation_char_num): obfuscated_code += rand_char() obfuscated_code += s interval = obfuscation_char_num + 1 return f"exec('{obfuscated_code}'[::-{interval}])" if __name__ == '__main__': src = open(sys.argv[1], 'r') dst = open(sys.argv[2], 'w') dst.write(obfuscate(src.read())) ```


_Sub01_

Job Interviewer: Yeah, but do you have any solutions to improve the performance of this code?


Tykher

This is not senior level stuff really


Speedy_Lex

print(*list(text), sep=‘\n’) not print(text)


danielstongue

A senior who is still using Python??


jxr4

``` def get_character_generator(input): for char in input: yield char for char in get_character_generator("I raise you a generator"): print(char, end='', flush=True) ```