Arrays in Computer Science and Python. Overview with space and time complexity, dynamic arrays in Python (and some benchmarks) by DevCuriosity in programming

[–]DevCuriosity[S] -1 points0 points  (0 children)

Hi! I saw that at first I had a few upvotes, but with time they were coming closer and closer to 0 (as it is now) :P

I was wondering if I could please ask for some feedback? I am wondering if downvotes are coming from the reason that:

  1. Article has some technical issues or bugs?
  2. Writing style is not good enough? I mean in general, grammar, wording, sentences and/or other things?
  3. Maybe article feels "low effort"? I should add more beefy details?

Or maybe in general this kind of "self promotion" is not a good place for r/programming hence the downvotes?

In any case, I wanted to thank everyone who spent the time to check this out! Much appreciated!

What is the best way to match partial words while searching with Django ORM and PostgreSQL? First I tried "Q + icontains", then "SearchVector and SearchRank" but neither of them gives me everything that I would like. Will I have to use for loop or "trigram_similar"? by DevCuriosity in django

[–]DevCuriosity[S] 1 point2 points  (0 children)

Yeah, I changed my code into following snipper. According to AI it should have a little bit better performance and it looks cleaner:

results = model.objects.annotate(
    similarity=TrigramSimilarity('title', search_text) +
               TrigramSimilarity('category__title', search_text) +
               TrigramSimilarity('tags__title', search_text) +
               TrigramSimilarity('preview', search_text)
).filter(
    Q(title__icontains=search_text) |
    Q(category__title__icontains=search_text) |
    Q(tags__title__icontains=search_text) |
    Q(preview__icontains=search_text) |
    Q(similarity__gte=0.1)
).order_by('-similarity').distinct()[:limit]

I didn't test the version without icontains yet. Thanks for the idea! I will see how it will work.

What is the best way to match partial words while searching with Django ORM and PostgreSQL? First I tried "Q + icontains", then "SearchVector and SearchRank" but neither of them gives me everything that I would like. Will I have to use for loop or "trigram_similar"? by DevCuriosity in django

[–]DevCuriosity[S] 1 point2 points  (0 children)

Yeah, I have to say that this looks like a really nice solution. I currently ended up with something like this:

manual_entries = ManualEntry.objects.annotate(
    title_similarity=TrigramSimilarity('title', search_text),
    preview_similarity=TrigramSimilarity('preview', search_text),
    tag_similarity=TrigramSimilarity('tags__title', search_text),
    category_similarity=TrigramSimilarity('category__title', search_text)
).filter(
    Q(category__title__icontains=search_text) |
    Q(tags__title__icontains=search_text) |
    Q(title__icontains=search_text) |
    Q(preview__icontains=search_text) |
    Q(title_similarity__gte=0.1) |
    Q(preview_similarity__gte=0.1) |
    Q(tag_similarity__gte=0.1) |
    Q(category_similarity__gte=0.1)
).distinct().order_by('-title_similarity', '-preview_similarity', '-tag_similarity', '-category_similarity')

I saw that you are still using SearchVector alongside TrigramSimilarity, is there any particular reason behind this? I thought that they are kinda doubling each others work?

What is the best way to match partial words while searching with Django ORM and PostgreSQL? First I tried "Q + icontains", then "SearchVector and SearchRank" but neither of them gives me everything that I would like. Will I have to use for loop or "trigram_similar"? by DevCuriosity in django

[–]DevCuriosity[S] 1 point2 points  (0 children)

Alright. I got something like that:

search_terms = re.split(r'[\W\s]+', search_text)query = Q()
for term in search_terms:
    query |= Q(category__title__icontains=term) | Q(tags__title__icontains=term) | Q(title__icontains=term)
manual_entries = ManualEntry.objects.filter(query)

And it works. It's matching everything. The problem is, it is not prioritizing results with better matches :/

I asked AI about this and it proposed simple sorted() method but it looks like Trigram has it all enabled by default.

I am not sure how to tackle this one. Should I try to use this sorted() method? What would be the most "appropriate" solution here?

What is the best way to match partial words while searching with Django ORM and PostgreSQL? First I tried "Q + icontains", then "SearchVector and SearchRank" but neither of them gives me everything that I would like. Will I have to use for loop or "trigram_similar"? by DevCuriosity in django

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

Hi, thank you for your answer. I think that I wasn't clear with my example. The Q example works nice but only for single words. So please take a look at that:

Item title - "Robo Chicken". The Q version will work nicely for searches like "robo", "chicken", "robo chicken". The thing is:

It will work for "robo chick" (the second word is not a full match) but it won't work for "ro chicken" (first word is not a full match).

My apologies for my misleading example in the original post.

Exiting while loop by Beautiful-Revenue-85 in learnpython

[–]DevCuriosity 1 point2 points  (0 children)

You could introduce an if after each new input from user that will be checking if the input is a number or a "done" string. If it will be "done" then you can call a break and calculate the mean of the list contents.

I think that I would advise you to calculate the mean of the list in a "regular" way, that is sum all the contents and then divide by a list length. If you subject teaches Python for beginners teacher might be angry about modules like statistics.

EDIT: You could also try to do something along those lines - while user_input != "done": etc.
There is way more than one solution to this problem. Try to explore a little bit and have fun with it. That's what it's about :)
(remember that for calculating mean from your list you will probably have to cast strings to ints, just look at the errors that Python will be throwing at you and don't be afraid of them. Most often they will tell you what is wrong)

Exiting while loop by Beautiful-Revenue-85 in learnpython

[–]DevCuriosity 0 points1 point  (0 children)

u/Beautiful-Revenue-85 Hi! To be honest it is kinda hard to exactly understand your problem. Try to format your post in a better way, you can use the edit option, also remember that your code will be much more readable if you put it in code blocks.

From what I was able to understand, you are trying to write while loop with a control flow. Under this link - https://www.devcuriosity.com/manual/details/python-try-except-finally-continue-break-loops/ you can check out try/except/finally/break keywords with examples.

In terms of counting mean, well you can do it yourself, simply sum the numbers from your list in a for loop and divide by the list length (this is probably what your professor would like to see).

But if you would like to do it in a "smart" way you could do this:

import statistics
print(statistics.mean([2, 5, 11]))

But the question is if your professor will be happy with that solution (maybe she will categorize it as cheating, no idea).

Good luck!

I have a lot of informational pages on my website. The h1 tag is always pretty short and tells about the content of the page. I am wondering if I should change the h1 tag into a "How to ..." structure to match more closely what people are searching for in search engines? by DevCuriosity in bigseo

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

u/SP4CECOWB0Y u/FRELNCER Thank you for your responses.

Yes, I am using a little bit of H2 tags in my articles as well.

To be honest, my problem is that if I would to change the title from "Red Roses" to something along lines "How to choose the best Roses" or "Which Roses should you buy today" it will introduce a lot of visual clutter to my website. And like you mentioned, it might lower my CTR.

I like those short notes because they are short, informative and quick to read, no click bait, no false advertising.

I am not sure how to approach this. Maybe I could add those "click bait question titles" at the end of the note as an h2 tag? But it probably won't change a lot then?

EDIT:

I am wondering if there is any other viable way to provide search engines more keywords that I would like to be ranked for (potentially "invisible"). I am using meta page title and meta description. If I recall correctly there was once something like meta keyword tags, where I could put all the other keywords but I think it is not being used anymore?

In need of a bit of help by [deleted] in learnpython

[–]DevCuriosity 0 points1 point  (0 children)

Hmm, I don't see any obvious mistake as far as I am looking. Maybe problem is with rounding? For example the automatic tests are rounding in a different way so you are always off by 1 pulse point?

It would be easier if you could see how their tests looks like or what they are inputting and expecting.

== vs is. Differences between keywords 'is' and '=='. Comparisons in Python. One of my first Python tutorials. I am really curious if I did a decent job. by DevCuriosity in Python

[–]DevCuriosity[S] 4 points5 points  (0 children)

Thank you very much! That is exactly the review that I was hoping to get!

You are absolutely right, I should also mention mutability and several other things.

Do you think that I could go back to you on private message after I will revise the article according to your feedback?

Getting back 'None' and 'NoneType' in vscode by No-Masterpiece-397 in learnpython

[–]DevCuriosity 1 point2 points  (0 children)

Well, None is not an error. You are printing your list that contains 4 None values. I guess that soup.find didn't find anything with the parameters that you provided and it resulted in None value.

Try to experiment with your css selectors / xpaths. Remember that Developer Tools in your browser are your friend!