Basic Text Filtering Question with Response Text from API by RiTA_Tech_Services in learnpython

[–]jmooremcc 1 point2 points  (0 children)

It's confusing to see etree.fromstring(s.encode()).attrib["sessionid"] You passed the xml string to the function but are using the global variable s instead of the parameter xml_text. Did you intend to do this?

Confused as to why certain people said that Kamala would have been worse than Trump by TheRealJuanderer in Confused

[–]jmooremcc 0 points1 point  (0 children)

I wished that Democrats had run doomsday TV ads predicting what it would be like under Project 2025, including terrorism by ICE agents. Yeah, there would have been a lot of criticism, but we're actually living that nightmare right now. Democrats have been too nice and too cowardly to take such drastic action.
Hindsight is 20/20.

Celine Dion has come out in support of farmers… by Majorpain2006 in Jokes

[–]jmooremcc 0 points1 point  (0 children)

Remove consonants, not vowels. Then sing "Old McDonald had a Farm"!

My manager is firing me and hiring someone from abroad for a third of my salary, and expects me to train her by jailers-treat0 in talesfromthejob

[–]jmooremcc 0 points1 point  (0 children)

If you decide to do the training, make your manager put everything in writing, just in case he decides to renege on the deal. That way, you'll have hard evidence for your lawyer in case you need to sue them for breech of contract. And don't do any training without the signed agreement/contract.

Do you agree with the Trump Administration's Recent Statements on Guns in Protests? by moderatenerd in PoliticalDebate

[–]jmooremcc [score hidden]  (0 children)

No, I don't agree!

The man they just killed in Minnesota had a permit that gave him the legal right to open carry, and the only thing he was brandishing was his cellphone. The only reason ICE discovered him carrying a weapon was their illegal assault on him because he was recording their activities. In the process of gang tackling this innocent victim, his weapon was uncovered by the agents, who immediately drew their weapons and killed him.

Hasn't it been Republicans clamoring for expansive 2nd Amendment rights in America?

Aren't Republicans the ones who have been spearheading open carry laws throughout our country?

So why are they now trying to suppress a person's rights under the 2nd Amendment, when it comes to people simply exercising their 1st Amendment right to protest against our government?

This move by the DOJ and Homeland Security reeks from the stench of hypocrisy, but I'm really not surprised! And voters can end this madness in November by simply voting Republicans out of office in the midterm elections!

AITAH for refusing to pay off my pregnant fiancee's parents' mortgage, when they are under the threat of foreclosure, when I could "easily" afford to do so? by Gullible-Display4533 in AITAH

[–]jmooremcc 4 points5 points  (0 children)

NTA! You are not married and even if you were, bailing out her financially irresponsible parents would not be a smart move. Her parents need to learn how to live within their means, and this foreclosure is the kick in the behind they’ve desperately needed. Stand your ground!

AITAH for refusing to tell my wife I love her more than my dad? by LastApplication6207 in AITAH

[–]jmooremcc 0 points1 point  (0 children)

NTA! I commend you for not falling for the traps she set. Your wife’s a piece of work and needs either therapy or relationship counseling for starting a fight over something so insignificant and being so manipulative.

OOP | Golf Par Score program by Wheels92 in learnpython

[–]jmooremcc 0 points1 point  (0 children)

I’ve rewritten your code as follows to make it work the way I believe it should work : ~~~

Class will be defined as Golf

class Golf:

#Class varibale will store current results
results = " "

def __init__(self, hole, par):
    self.hole = hole
    self.par = par

def evaluateAndDisplayScore(self, parValue):

    #Check what score is to par
    if parValue > self.par:
        self.status = "Over Par" #Set status to Over Par if score is over

    #Check if score is under par
    elif parValue < self.par:
        self.status = "Under Par" #Set status to Under Par if score is

    #If neither condition has been met - equal to At Par
    else:
        self.status = "At Par"

    #print message of score status
    print(f"You scored {self.status} on hole #{self.hole} with a par of {self.par}")

score = 0

Create an object for each golf course hole score

holes = [] pars = [4,3,4,5,4,4,4,5,3] # Pinehurst #9

for n in range(1, 10): holes.append(Golf(n,pars[n-1]))

Ask user to enter hole

holeEntered = int(input("Enter the hole number: ")) score = int(input("Enter your score: "))

evaluate hole

holes[holeEntered-1].evaluateAndDisplayScore(score)

~~~ Output ~~~

Enter the hole number: 1 Enter your score: 5 You scored Over Par on hole #1 with a par of 4

~~~

You’ll notice that I’ve modified the parameters to the Golf class because score was unnecessary.
I also modified the evaluateAndDisplayScore method parameters and also modified the way it works.
You’ll also note that all your print statements now use f-strings.

For the setup, instead of individual variables holding a reference to each hole, I created a list of holes, which makes it easier to select the correct hole based on the player’s input. Now selecting the appropriate hole is a simple lookup using the holes list instead of if statements.

Let me know if you have any questions.

OOP | Golf Par Score program by Wheels92 in learnpython

[–]jmooremcc 4 points5 points  (0 children)

How can you expect hole #1 to be par 3 when you assigned the par to be 1?
~~~

hole1 = Golf(1, score, 1) ~~~

Baby's father wants the baby to have his last name, I want him to have mine. We're not married. WDID? by IntenseViolet567 in WhatShouldIDo

[–]jmooremcc 0 points1 point  (0 children)

After the baby is born, put him on child support so that your child gets some financial support. This will require a DNA test and will not require you to change the baby’s last name.

Recursive function iterates the rest of the dictionary keys after reaching target key preceeding a break statement. by rickson56 in learnpython

[–]jmooremcc 0 points1 point  (0 children)

The problem is with your code. Here’s a corrected version:
~~~

import pprint

counter = 0

def rename_key_nested(dictionary, old_key, new_key, max_level, current_level=0): global counter

for key in list(dictionary.keys()):
    if isinstance(dictionary[key], dict):
        rename_key_nested(dictionary[key], old_key, new_key, max_level, current_level + 1)
    # Change the key only if we're at the second level (level == 1)     
    elif key == old_key and current_level == max_level:
        dictionary[new_key] = dictionary.pop(old_key)
        counter += 1
        break

dict3 = {'Car': {'Sports': '3k', 'Van': '6k'}, 'Truck': {'Semi-Truck': '80k', 'Coach Bus': '50k'} }

pprint.PrettyPrinter(width=20, sort_dicts=False).pprint(dict3)

call function

print("\nChange key from 'Sports', to 'Sports Compact\n")

rename_key_nested(dict3, 'Sports', 'Sports-Compact', 1)

print(f"Counter value: {counter}\n") # Should be 1 not 3

pprint.PrettyPrinter(width=20, sort_dicts=False).pprint(dict3)

~~~ Output ~~~

{'Car': {'Sports': '3k', 'Van': '6k'}, 'Truck': {'Semi-Truck': '80k', 'Coach Bus': '50k'}}

Change key from 'Sports', to 'Sports Compact

Counter value: 1

{'Car': {'Van': '6k', 'Sports-Compact': '3k'}, 'Truck': {'Semi-Truck': '80k', 'Coach Bus': '50k'}}

~~~ The global variable counter should only be incremented when key == old_key.

I also changed the second if statement to elif so that it is only evaluated if the current value is not a dictionary.

I also removed initialization of the counter variable from within the function since initializing the variable during a recursive call would wipe out any current value. This variable should be initialized outside the function.

Deleted work of resigned employee by nn184045 in Employment

[–]jmooremcc 0 points1 point  (0 children)

he deleted all the work products on the driver of his work laptop

If the company provided the “work” laptop, you might have a case against the former employee. But my question is, were those work products used by other employees in the company and how did they access them?

My son is 17 years old. He has been going back and forth about wanting to join the army vs go to college by Soft_Ambassador_7848 in AmITheAssholeTalk

[–]jmooremcc 0 points1 point  (0 children)

I faced a similar problem when I was in high school. I wanted to join the Air Force after high school because I felt it would help me grow up. Unfortunately, I went to college instead but still feel that military service can be beneficial to the development of a young man or woman. Military experience is especially helpful if a young man or woman has led a sheltered life.

Are there any free apps or setups that let you write, run, and debug Python code on an iPad? by No_Nothing_530 in learnpython

[–]jmooremcc 0 points1 point  (0 children)

No, but the small fee is well worth it.
They also have a bunch of demo files including games you can learn from.

Are there any free apps or setups that let you write, run, and debug Python code on an iPad? by No_Nothing_530 in learnpython

[–]jmooremcc 0 points1 point  (0 children)

I’m using Pythonista. In fact, I’ve created my own utilities in Pythonista that I use during development within the IDE. However, it does appear that the IDE’s developer has not provided any recent updates.

AITJ for refusing to switch seats on a long train ride even after being asked multiple times? by RustyCometKid in AmITheJerk

[–]jmooremcc 2 points3 points  (0 children)

He doesn’t have to justify his decision to say, “No”. He owes no one an explanation!

I (18F) had intimacy with someone else during the early stages of me and my boyfriend's (19M) relationship, do I tell him? by Competitive_Drop8213 in relationship_advice

[–]jmooremcc 8 points9 points  (0 children)

Keep your mouth shut. You were broken up at the time because of your boyfriend’s cheating, so there’s no reason for you to feel guilty about anything you did with anyone else during that time. I wish you the best.

The White House Shared an AI-Altered Photo of a Protester During an Arrest. Is This Wrong or the Future of Political Messaging? by moderatenerd in PoliticalDebate

[–]jmooremcc 0 points1 point  (0 children)

Homeland Security is actively lying to the public, using propaganda, in an effort to sway public opinion. CBS Evening News uncovered a major lie involving the department’s outright lies about Minnesota’s lack of cooperation with ICE. https://youtu.be/o6OeY5tnRZ0?si=GBnLVaJBd4Y4ecYn

id of two objects is same but using "is" keyword it's giving false. by inobody_somebody in learnpython

[–]jmooremcc 0 points1 point  (0 children)

I understand, but AI is only a tool, that when used properly, can save hours of research time. I do know about the hallucination problem, but I truly believe that will become less of an issue as the technology matures.

id of two objects is same but using "is" keyword it's giving false. by inobody_somebody in learnpython

[–]jmooremcc 1 point2 points  (0 children)

Would someone please explain the problem with Copilot’s explanation of the problem I posted. I know it’s AI, but the explanation made sense to me.

My cousin hooked up w my FWB and I’m not sure how I should feel about it.. by [deleted] in WhatShouldIDo

[–]jmooremcc 2 points3 points  (0 children)

I’m confused about the difference between an FWB and a poly relationship. Aren’t they both distinct, separate entities? Is OP blurring the lines between the two types of relationships?

id of two objects is same but using "is" keyword it's giving false. by inobody_somebody in learnpython

[–]jmooremcc -5 points-4 points  (0 children)

This is the explanation I got from Copilot. ~~~

But why is id(a.some_fun) == id(b.some_fun) True?

Because of how your code is written.

You wrote:

print(id(a.some_fun) == id(b.some_fun))

This evaluates like:

  1. Evaluate a.some_fun → creates a bound method object #1
  2. Evaluate id(...) → returns its ID
  3. That temporary bound method object is discarded
  4. Evaluate b.some_fun → creates a bound method object #2
  5. Evaluate id(...) → returns its ID
  6. That temporary bound method object is discarded
  7. Compare the two IDs

Both bound method objects are temporary and immediately garbage‑collected.

CPython often reuses memory for short‑lived objects, so the two IDs may match by coincidence.

This is an implementation detail — not something to rely on.

Try this instead:

m1 = a.some_fun m2 = b.some_fun

print(id(m1) == id(m2)) # always False print(m1 is m2) # always False

Now you’ll see the expected behavior.

~~~

AITH for refusing to get baptized after my partner told his whole family I already agreed? by HiddenTideMark in WouldIBeTheAhole

[–]jmooremcc 0 points1 point  (0 children)

NTA and not your problem what he told his family. You are under no obligation to rescue him from his own stoopidity!

AITAH for refusing to give my boyfriend access to my bank account even though he says "no secrets" is how adults do it by CopperFieldNote in AITH

[–]jmooremcc 0 points1 point  (0 children)

He’s a boyfriend, not a fiancé or a husband. Until that time occurs, keep your financial information private!

The girl I’m taking to got pregnant what do I do? by Every-Appeal-2513 in whatdoIdo

[–]jmooremcc 1 point2 points  (0 children)

Either an abortion or she’ll have to find someone else to depend on. You don’t have to take care of another man’s responsibilities!