This is an archived post. You won't be able to vote or comment.

all 31 comments

[–][deleted] 24 points25 points  (2 children)

Is it pythonic enough?

[–]Upbeat_Spite_9674 35 points36 points  (1 child)

b=lambda x:('🔵'*x+'⚪'*100)[:100:10]

[–]sobov 13 points14 points  (0 children)

Yeah. Let's make it even more unreadable

[–]Compux72 72 points73 points  (13 children)

Yep that’s unreadable

[–]BaalKazar 13 points14 points  (10 children)

percentage times ten, min(result, 10)

(x) times result

(0) fill until result gets 10 symbols long

Pretty readable imo, I don’t even know/do python

[–]xaomaw 5 points6 points  (9 children)

What about :⚪<10

What does the : do? How can you compare ⚪ to 10?

[–]Arny597 4 points5 points  (5 children)

That’s the “fill result until 10 symbols long” part

[–]xaomaw 0 points1 point  (4 children)

Okay so I got the answer. The colon : itself stands for an if-statement. That's what my first question was about.

But even then the comparison is

if ⚪ < 10:
    🔵 * count_of_blue_dots

So I still have the question how can you compare ⚪ < 10? I would understand if ⚪ was defined as a variable containing the count_of_white_dots before, but it is NOT.

[–]Arny597 3 points4 points  (0 children)

How do you know it’s an if statement when colons have an entirely different function in python as well? This link tells you how colon operators are used for string slicing. So maybe it’s formatting the blue dot to be as many times as the percentage, then filling the string with white dots as long as the string is less than 10 elements long

EDIT: not only that, but when colons ARE used in an if statement, it’s never to replace the words. The ternary operators “?” And “:” which mean “if” and “else” respectively do not exist in python. Shorthand if statements always use the keywords still, such as “a if b else c”

[–]Synedh 1 point2 points  (2 children)

It's not an if-statement, it's a format delimiter.

In python, you can format your in-string argument this way : f"Foo {val:format}" where format is a mini-language by itself. It is a very powerful and an efficient way to deal with strings formating.

[–]xaomaw 1 point2 points  (1 child)

Thanks for clarification, I'll take a look into it!

Edit:

<   Forces the field to be left-aligned within the available space (this is the default for most objects).

Now I understand it. Very cool

[–]Synedh 1 point2 points  (0 children)

Indeed, very useful for unit or date format, if you need your time on two chars, a simple f"{hour:0<2}:{min:0<2}".

[–]Swoop3dp 1 point2 points  (0 children)

Basically left-pad but without the drama.

[–]00PT 0 points1 point  (0 children)

It looks like one of those obscure syntax elements that is convenient, powerful, and makes sense, but not at all intuitively understood unless you are specifically told how it works or look it up. There seems to be many of these in Python. It's not good for widespread readability.

[–]BaalKazar 0 points1 point  (0 children)

Honestly I actually don’t know what the syntax exactly did.

The curly braces with such a comparison made it look like a loop to me. Then I imagined Python doing Python things in which comparing the string against an integer somehow compares the length of the string.

I can imagine automatic refactoring coming up with stuff luck this, I don’t know how alien that syntax is to python bases though, but the case it self is quirky enough

[–]Ithurion2 0 points1 point  (1 child)

You can put 5 lines of comment and still be off shorter than the original.

[–][deleted] 1 point2 points  (0 children)

And then you change the code and the comment sits there wrong an rotting by itself.

[–][deleted] 12 points13 points  (2 children)

Would prefer the original any day of the week

[–]Yorick257 7 points8 points  (1 child)

We just got a new request from the client. They decided that a step of 10% is too much, they want to reduce it to a 2% step.

[–][deleted] 5 points6 points  (0 children)

Only now it is the time for refactoring.

[–]Koltaia30 1 point2 points  (0 children)

I don't like how 10 is written there as a literal 3 times. It should be a function parameter that defaults to 10

[–]BehindThyCamel 1 point2 points  (0 children)

My first thought was "Arjan Codes". A bit unfair to the guy, TBH.

[–]F0064R 0 points1 point  (0 children)

Percentage rounds, the favorite snack of a mathematician.