+13

# How to One-line this code ?

I want to oneline this exact code . [ alt solutions are not welcomed ] ------------------------------------------------------------------- | | ------------------------------------------------------------------ https://code.sololearn.com/cWmfkW3j2Pnu/?ref=app

9/11/2019 12:16:45 PM

Mirielle👽

+23

There was a time I wanted to one-line everything at all costs. I thought it was cool, but now I don't. Not only is your code hard to understand when you revisit it months later, but it's really slow. print((lambda f: lambda n: f(f,n))(lambda g,x: 1 if x<2 else x*g(g,x-1))(42))

+7

Diego one month after [globals().__setitem__("fact", lambda n:1 if n==0 else n*fact(n-1)), [print(fact(5))]]

+5

Thomas Williams, doesn't seem to run.

+4

Coding Einstein , Diego is the master not me haha, i've been trying to do that all by myself and it takes a month

+3

HonFu it does... Enter a number

+3

Diego that works but it kind of looks like a new solution to me [ i still want my code ] just with some little changes to make the print() function be inline with fact. Maybe wrapping fact up in a parentheses or something 👀. Without using semicolon (;)

+3

Thomas Williams yes I know but they are literally on one line that is why I said it jokingly

+3

Ah sorry Coding Einstein[Back 2 school[Less Active 😲]] . Sarcastic/Joking voice tones do not convey well via text

+3

Thomas Williams yeah man

+2

Thomas Williams it showing an error: NameError

+2

Cbr✔[ Exams ] oof I think it registered your method when I callled ot in testing. Ill fix it

+2

Cbr, I tried that. 'fact is not defined.'

+2

HonFu yes it doesn't

+2

Cbr✔[ Exams ] Crap. Ill need to get to a real interpreter to effectively solve the problem

+2

Great best

+2

Cbr✔[ Exams ] why not just do fact = lambda n:1 if n==0 else n*fact(n-1);print(fact(int(input()))) at least it is in one line lol you can add a semicolon to compete a stateement on a line

+2

; starts a new statement/line. There's no art in stringing up several statements in one line instead of hitting return.

+2

Well HonFu and Coding Einstein[Back 2 school[Less Active 😲]] , semi-colons do not count as one-line codes

+2

That's what I said.

+2

Ah I see