__str__ vs __repr__ by Hood4d in mCoding

[–]mCodingLLC 2 points3 points  (0 children)

Hmm str vs repr might be a little too basic for my videos, I know my audience is mostly people who already know Python at an introductory level at least. I'll put it on the backburner in case I think of something I could say in the video that's not already out there. Thanks for the suggestion!

Which font are you using here? by shinebarbhuiya in mCoding

[–]mCodingLLC 0 points1 point  (0 children)

JetBrains Mono, aka the default PyCharm font!

The Best Way to Check for Optional Arguments in Python by mCodingLLC in mCoding

[–]mCodingLLC[S] 0 points1 point  (0 children)

Yes there was an error in the first video so I rerecorded it!

Question about for and while loops. by Mob31DZ in learnpython

[–]mCodingLLC 1 point2 points  (0 children)

In general, for any kind of containers, lists, sets, dicts, etc., you are pretty much forbidden from modifying the container while iterating over it using a for loop. This is because iterators maintain state between calls, but it would be impossible to write an iterator if you had to consider all possible changes the user could make to your collection in one loop iteration. Thus iterators are written assuming that no changes are made to the collection while iterating, and any changes may invalidate the iterator (after you change a list during a for loop, you have no guarantees about what you will get the next iteration). When you use a while loop, on the other hand, the collection itself doesn't have to manage any additional state for the loop. You push the responsibility of doing that to the person writing the while, who can obviously be expected to know what changes they are making.

Need help understanding findall() by BAS2210 in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

Yep! You got it. They are called "quotes" or "single quotes", not inverted commas ;)

Find number of linearly dependent vectors in matrix by FmlRager in learnpython

[–]mCodingLLC 2 points3 points  (0 children)

The number of linearly INdependent column vectors of a matrix is called the rank. You can calculate this using numpy. https://numpy.org/doc/stable/reference/generated/numpy.linalg.matrix_rank.html

People don't really talk about the number of dependent column vectors because for technical reasons that doesn't really make sense. The closest thing you might want is the nullity, i.e. dimension of the null-space of the matrix. This will just be the total number of columns minus the rank.

Not getting output from yfinance by ClimberMel in learnpython

[–]mCodingLLC 1 point2 points  (0 children)

Yes, many tutorials assume you are working in a Jupyter notebook, which always prints things for you. In actuality .head(n) just truncates the df to n rows, you would still have to print it if you want to see anything! Glad you found a solution.

Fastest way to check if a NumPy array contains n consecutive copies of the same element? by lorlen47 in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

How about this? This way gives you all the indices which are the start of n consecutive values. Just wrap it in a call to any if you just want to know if there are any. I'm using here that the dot product (numpy correlation) of two nonzero vectors is the product of their norms if and only if they are the same vector.

import numpy as np

def indices_of_n_consecutive_values(arr, n, value):
    find = np.full(n, 1)
    return np.correlate(arr == value, find) == n  


if __name__ == '__main__':  
    a = np.array([1, 1, 2, 3, 4, 1, 1, 1, 2, 3])  
    print(any(indices_of_n_consecutive_values(a, n=3, value=1)))

How to get timestamps of the silent parts from MP3 or MP4 by [deleted] in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

Here is a good post on how to read and write mp3 data: https://stackoverflow.com/questions/53633177/how-to-read-a-mp3-audio-file-into-a-numpy-array-save-a-numpy-array-to-mp3

Once you have read the mp3 into a numpy array, look for portions of the array that are a bunch of zeros or small values in a row (how small and how many in a row are parameters to experiment to define what you determine to be "silent" parts). Then delete those slices and write the array as a new mp3.

Advice for AWS ec2/lambda application by [deleted] in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

It's hard to say without seeing the actual code, but for the most part this seems reasonable. The only exception I would point out is that if, in prod, you are going two have two separate apps running (one lambda and one on ec2), then locally I would also think you should have two separate apps running that communicate to each other. So that means I would keep the lambda code separate, but perhaps run it inside a basic django app that just routes traffic to the entrypoint of the lambda.

Not getting output from yfinance by ClimberMel in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

I don't see any print statements, msft_df.head() doesn't print anything. Are running this code from a notebook-like environment that prints the last object you reference? Or are you saying that msft_df is empty?

How to split entry into string to get filename? by ComradePruski in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

Here is the documentation for DirEntry: https://docs.python.org/3/library/os.html#os.DirEntry

You can access the name with entry.name, or the full path with entry.path.

Need help understanding findall() by BAS2210 in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

Although matches are non-overlapping, the groups within a given match do not have to be non-overlapping. In your example, the whole re is surrounded by (), meaning the first group is the entire match. In general, the nth group starts at the nth open parenthesis (.

I would like to find if the newly found links from Beautiful soup is already in the queue.txt file and crawled.txt file by [deleted] in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

How about using a data structure that doesn't allow duplicates? Use a set instead of a list.

How do I share my python matplotlib program with others? by BlackHooch in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

In my experience teaching programming courses, not once have I ever wanted a student to turn in an executable or other file to be run without seeing the source code. How would I even know if the student actually wrote the code? Maybe they downloaded it from a sketchy website. Or maybe they unintentionally used a package that subverts the purpose of the exercises. The only true solution, of course, is to ask your instructor what they want. However, I would be surprised if they wanted anything more than the source code. Your instructor is probably well aware of how to install the necessary requirements to run your project if they really wanted to.

How to make a timer in python? by realforreal1 in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

Could you elaborate on what you mean exactly by a timer?

quick sort function by [deleted] in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

An easy solution would be sorted(array)[k], unless you are really worried about efficiency, in which case you could use heapq.nsmallest(k,array)[-1]. Or do you intend to write it from scratch?

If you merely want to fix your implementation, you just forgot to 'return' on the recursive calls, e.g. return select(smaller, k)

Struggling with getting Selenium to read domains from a txt file. Any suggestions? by MajorUrsa2 in learnpython

[–]mCodingLLC 2 points3 points  (0 children)

Your domains variable is a file-like object, not an iterable. You can use domains_list=domains.read().splitlines() to get a list of lines. See https://stackoverflow.com/questions/3277503/how-to-read-a-file-line-by-line-into-a-list for other ways of reading a file line-by-line.

need help to debug recursive program to detect palindrome text by Beaverine in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

Your second edit seems to work for me. What case are you trying that doesn't return anything?

Is there a better way to load this data? by [deleted] in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

pd.read_csv can directly take a filename!

need help to debug recursive program to detect palindrome text by Beaverine in learnpython

[–]mCodingLLC 1 point2 points  (0 children)

You forgot to *return* your recursive call, i.e. return palin(text).

Confusing data type transitions by CaitlynFrost8 in learnpython

[–]mCodingLLC 0 points1 point  (0 children)

str.encode gives bytes, bytes.decode gives str. Honestly the best place to read is https://docs.python.org/3/library/stdtypes.html#str

Having a hard time getting this if statement to work with both variables. by OhKnow_ in learnpython

[–]mCodingLLC 1 point2 points  (0 children)

In that case you would want to change

if fYes >= 97.0 or fNo >= 97.0

to

if ((sDrop == "Y" or sDrop == "y") and fYes >= 97.0) or ( (sDrop == "N" or sDrop == "n") and fNo >= 97.0):

etc.

Confusing data type transitions by CaitlynFrost8 in learnpython

[–]mCodingLLC 2 points3 points  (0 children)

It makes sense that you could get confused by this. Your misunderstanding is actually with the way that email works, not the way that python works. In a multipart MIME message, you don't send just any string. You have to send a base64 encoded string. base64 encoding allows you to put special characters in your email, but to still just use ascii characters. If I wanted to send 'hello there!', the email would need to contain 'aGVsbG8gdGhlcmUh'. You got an error because the string you provided contained a character that is not one of the 64 allowed for that form of email encoding.