function

How to calculate a function with different equations depending on different ranges?

How to calculate a function with different equations depending on different ranges? Question: I am trying to calculate this equation in python. However I seem to be unable to perform the logic operation as had to use array in np to create the decimal range. I wonder if there is an alternative method of creating …

Total answers: 6

Why calling assigned lambda is faster than calling function and lambda (not assigned)?

Why calling assigned lambda is faster than calling function and lambda (not assigned)? Question: Why calling an assigned lambda in python3.11 is faster than: calling function lambda that isn’t assigned Why this happens only (maybe) on python 3.11 and not 3.7? I tried this: Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit …

Total answers: 1

Making sympy function with 2 variables

Making sympy function with 2 variables Question: I´m trying to do a piecewise function with sympy, but I can´t. It doesn´t the piecewise function. I want a simple funtion when (x,y) != (0,0) and a when (x,y) = (0,0) Can someone help me ? Thank you so much I tried this code: f_exp = sp.Piecewise((((x*y)*(x**2 …

Total answers: 1

Nested dictionary for loop with def (INDENTENTION PROBLEM)

Nested dictionary for loop with def (INDENTENTION PROBLEM) Question: I am learning Python with the 2°Ed. Automate the boring stuff with python, and I came across with a indentention problem. Can someone explain what I am doing wrong? I am trying to add a indentention after the for loop to insert the num_brought value, but …

Total answers: 1

a function that calculate the total cost of each order from a dictionary

A function that calculate the total cost of each order from a dictionary Question: I have a list of dictionaries that represent orders in an online store. Each dictionary contains keys for the order ID, customer ID, and a list of line items, where each line item is itself a dictionary containing keys for the …

Total answers: 1

Check if parameter in string is followed by a specific letter – python

Check if parameter in string is followed by a specific letter – python Question: I found a similar answer for this but only in java. Here is an example of my code at the moment: def find_x(phrase, target): i=phrase.find(target) if ‘x’ in phrase[i+1]: return True else: return False I then realized in the case the …

Total answers: 1

Counting positive words in a passage python

Counting positive words in a passage python Question: I have to count the times positive and negative words appear in a passage. I have a list of positive words, list of negative words, and a passage excerpt. pos_words = [‘happy’, ‘like’, ‘love’, ‘good’, ‘favorite’, ‘best’, ‘great’, ‘amazing’, ‘joyful’, ‘positive’] neg_words = [‘sad’, ‘dislike’, ‘hate’, ‘angry’, …

Total answers: 3

What do parameters in my specific function mean?

What do parameters in my specific function mean? Question: Im currently solving an algorithmic task with Python and I got this function, which I should finish: def solution(nums: Union[List[int], Tuple[int, …]]) -> int: I don’t understand what does those thing mean in function. What is nums:? What does nums: Union[List[int], Tuple[int, …]] mean at all. …

Total answers: 3