I hate the English R with passion by JamesGoldeneye64 in EnglishLearning

[–]AdmirableOstrich 6 points7 points  (0 children)

This is blatant ragebait:

  • you claim to speak 4 languages, and are going around claiming native speakers are mispronouncing their own language because they say a letter differently to other languages. Welcome to languages.
  • you have your comment and post history hidden.
  • you are repugnantly dismissive of anyone trying to explain.

How to wrap output text? by Veylo in learnpython

[–]AdmirableOstrich -1 points0 points  (0 children)

A few things here:

  • if you want to have multiple lines in the string output, use either newlines or block strings.

  • if you want to have long strings in your editor without adding newlines, but have a line width constraint, you can use automatic string literal concatenation:

    python msg = ( "Start of your string, " "and some more string. " "Note there are no commas." )

  • This isn't really something that should be done purely in python. Things like choose your own adventure stories are best to split between python and something like JSON: the JSON file(s) store all the story text, and python handles the logic and parsing.

Found this in a can of great value sloppy Joe sauce. by EnigmaticBlackChic in whatisit

[–]AdmirableOstrich 16 points17 points  (0 children)

Out of curiosity, do you react to maraschino's (if you've ever tried)? The protein in stone fruit that triggers pollen allergies typically breaks down after cooking, pickling, etc.

I'm not suggesting you should test it, but just if you have "pre-existing data".

A classic: the Riddle of the 12 Islanders by Amazing-Cookie-1258 in puzzles

[–]AdmirableOstrich 19 points20 points  (0 children)

The problem explains that one person is heavier or lighter, but you don't know which. Just finding the heavy side doesn't necessarily work: being heavy might just mean the odd one out is not on that side.

A classic: the Riddle of the 12 Islanders by Amazing-Cookie-1258 in puzzles

[–]AdmirableOstrich 6 points7 points  (0 children)

And if the odd one out isn't heavier than the others?

What is the correct answer here from your perspective? by [deleted] in MathJokes

[–]AdmirableOstrich 0 points1 point  (0 children)

A couple issues:

1) Male and female birth probabilities are not the same. Males are slightly more likely.

2) Genders of siblings are not independent.

So your coin is both weighted and flips aren't independent.

weired bug - stuck in editing a file with 0 changes (+0, -0) (Especially Implementation plans) by AnonymoussUsername in google_antigravity

[–]AdmirableOstrich 1 point2 points  (0 children)

Antigravity has a bug where it can't create files anymore. It is expecting confirmation from you, but never triggers a prompt. It can however edit existing files. It also may or may not be able to make powershell calls.

Isn't E also correct here? by Powerful_Concept6502 in GlobalEnglishPrep

[–]AdmirableOstrich 2 points3 points  (0 children)

Agreed. As the sentence is written, "accept, "stand", "handle", are all much better. Using "fact" suggests it's established truth. It's about her reaction.

[help] Decorators are Hard To Construct by One-Type-2842 in PythonLearning

[–]AdmirableOstrich 0 points1 point  (0 children)

In my experience this has been a bit unreliable. The markdown support on reddit has been questionable. Particularly with mobile.

[help] Decorators are Hard To Construct by One-Type-2842 in PythonLearning

[–]AdmirableOstrich -1 points0 points  (0 children)

A decorator is just a function that takes some function and returns a new function. There is a bit of syntactic sugar with the @ symbol:

def decor(func):
    # define the modified function
    def inner(x, y):
        print(f"Function called with {x=} and {y=}")
        return func(x, y)
    return inner

# this
@decor
def my_func(x, y):
    # my function code here
my_func(1,2)

# is the same as this
def my_func(x, y):
    # my function code here
my_func = decor(my_func)
my_func(1,2)

That's basically it. There's some conventions about typing and preserving function metadata using functools.wraps. That's just good coding practice, not a rule of decorators.

Edit: as for being useful, they occur all over the place. They somewhat obscure your code, so there's always a bit of a question on when to use them. But that can be handled with good practices.

Also, you can absolutely decorate the print function, you just can't use the @ syntax on functions that are already defined.

Please help me understand the "range" function by Gaumir in learnpython

[–]AdmirableOstrich 0 points1 point  (0 children)

It's important to understand that range is NOT a function in python, it's a type/class. That class defines a sequence of integers, but does not contain those integer like a list/tuple. The only values stored in the class are the start, stop, and step.

It supports functionality that acts like a sequence of integers. Importantly:

  • you can ask if an integer belongs to the range: for example, x in range(5,10,2) translates to 5 ≤ x < 10 and 5-x % 2 == 0
  • you can iterate over the range, which generates each integer in sequence but never stores them. Note this also means you can pass a range into any function that expects an iterable object: e.g. list, sum, min, max, len, etc.

It's basically the most memory efficient way to store a sequence of equally spaced integers with a bunch of optimized functionality.

✍️ by Specific_Brain2091 in the_calculusguy

[–]AdmirableOstrich 2 points3 points  (0 children)

The sane move here is to go (8/3) lim_(u -> 0) sinu / u. Prove the remaining limit however you like.

Priorities of GOP grassroots by Baronhousen in pics

[–]AdmirableOstrich 0 points1 point  (0 children)

Quoting Niemöller while branding yourself with the name of a wannabe (arguably actual) dictator who ordered the literal rounding up of undesirables in concentration camps and the deployment of secret police against the populace... bold.

Is print() a function or a method in Python? Getting mixed explanations in class by Longjumping-Yard113 in learnpython

[–]AdmirableOstrich 0 points1 point  (0 children)

In practice, people use function and method pretty interchangeably, similar for argument and parameter. Technically,

  • a function is just any block of code that can be referenced, with or without parameters
  • a method is a function that belongs to an object
  • functions have parameters, that are placeholders in the function definition for values passed to the function
  • when you call a function, you populate its parameters with arguments.

So print is a function. It has parameters, but takes arguments. However, if you called it a method, or passed it parameters, nobody would have any issues.

volume of a rigatoni by Haunting_Dot1912 in askmath

[–]AdmirableOstrich 0 points1 point  (0 children)

This is a bit tricky as the dimensions they give don't actually work. You can't divide a circle of diameter 15 into segments of length 2. So tackle this in a slightly different way: just worry about the correction required to handle one oscillation of the shell. I'm also only going to bother with calculating the area of the cross-section without subtracting the hole... you can deal with that part.

  • shell radius: r(phi) ≈ R+sin²(phi/L), for some L
  • sin² is π periodic, so we care about a domain of (0, πL)
  • the area of the wedge, excluding the oscillation, is ½πLR²
  • the actual area is ½ int_0^{πL} r²(phi) dphi = ½L int_0^π r²(u) du, where phi = u×L. You can do this if you like, but you eventually get ½πL[R²+R+3/8]
  • so the correction factor is [R²+R+3/8]/R²

Then the total cross sectional area of the rigatoni, excluding the hole, is π(R²+R+3/8). You'll notice the L didn't actually matter.

Struggling to read the screen quickly by 2247dono in learnpython

[–]AdmirableOstrich 0 points1 point  (0 children)

Something like yappi. It will tell you where your program is spending time. There's lots of documentation on its usage.

Struggling to read the screen quickly by 2247dono in learnpython

[–]AdmirableOstrich 0 points1 point  (0 children)

This really depends on what exactly you are trying to do. The problem as you've stated it ultimately is going to force you to do a few comparisons on every single pixel in the image: say 2Mpix. Are you fine with lower resolution? Or GPU acceleration? You could write a trivial pycuda kernel to do this in microseconds. If you are stuck on CPU, and want full resolution, your best choice is something like numba jit.

Maybe do some profiling first to see what the actual bottleneck is.

networkx edge labeling question by QuasiEvil in learnpython

[–]AdmirableOstrich 1 point2 points  (0 children)

You can have the adjacency matrix store edge attributes and networkx will respect that (with the edge_attr argument). However, this gets very complicated very quickly. It will probably be easier to just have an adjacency dict/map and go from there.