i want to input the file name in this case books.txt and get the lines but i cant get it work, i have the files in the same directory but when i run this nothing happens, any way to fix this? or to call that function in another .py file but this return nothing and i dont know what to
Tag: function
Python Function is returning none although there is the original Value instead of copy
I have a code where I zero a column or row if it contains zero , I have my own function but when I use it it returns None , I made a copy of my matrix and performed changes on it and then I converted the values to the original one and yet I still get no return .
@lru_cache decorator excessive cache misses
How can you configure lru_cache to key its cache based on actual values received, rather than how the function was called? In other words, only the first call above should be a cache miss, the other two should be cache hits. Answer To do that, you would have to go through the process of binding arguments to formal parameters. The
Finding intersections between two lists
Edit: I was using Jupyter notebook, I had two different scripts in a row while working, The script shown here is one, and the error shown here is from the other script. (mistake) Thanks for your time! I intentionally learned more though. I’m trying to find an intersection between 10000 randomly generated lists of 6 elements numbers between 1 to
Adding functions y(x) together in python – impossible?
I’m currently trying to solve an engineering problem where I need to solve relatively long differential equations, for which I’m using the method odeint from scipy. I changed my problem to more easy variables and equations to shorten the code below and make it clearer. I want to add two parts of a function, here f and g, to build
Call Python function using dynamic string variables
I am trying to create a dynamic method executor, where I have a list that will always contain two elements. The first element is the name of the file, the second element is the name of the method to execute. How can I achieve this? My below code unfortunately doesn’t work, but it will give you an good indication of
How to edit this simple function to correctly sort letters and words in list alphabetically (Python)?
The objective is to take a list of strings, sort the letters in each string, and then sort the full list. We want to modify the list in place (so, use sort() rather than sorted()). My function: So, this means I would expect: To return “abc”, “bbd” This doesn’t work though. Can anyone suggest how to amend this function to
How to find the maximum x value of a function?
I need to find the maximum x value associated to the maximum y value of the following function that I plot using Python matplotlib module: Hence, the trend is this one: If I use the max() function in such way: It prints only the maximum y value (that in this case is equal to 0.8306243772229114). How can I do to
Receive print content of another class at execution time not after the end of the function
What I have tried: In class B I want to get print content in class A and add ‘Time is:’ to the beginning and print it in console. One solution is to return i as a list at the end of function, but I want i as instantaneous, not when the function is fully executed. The code I wrote does
Unique lists within list of lists if those lists have list as one of the elements
If I have: What would be the best way to get: If I try: I get TypeError: unhashable type: ‘list’. I don’t want to remove all layers of nesting, because that would just combine everything into one list: Output: If two instructors have the same count (i.e. 3 in this case), then only one 3 remains because it’s a set,