#๐Ÿ”’ Code is not going on to the next index

19 messages ยท Page 1 of 1 (latest)

mighty reef
#

So I am using spaCy to help me with identifying the gender of the author of a subreddit text, for example:
"AITA for not watering the plants, I (24F)..."
It would look something like this and what I want to do is get the pronoun ("I", "My", "Me", etc) and confirm the gender of the author. (Over here it would need to identify "I (24F)").
But the issue is, when it finds the gender of another person lets say "my girlfriend (24F)", then it just gets stuck on "girlfriend" cuz it has 24F so it will infinitely look at this.
So here is my code:

for s in shape_list:
    if s in ["ddX", "ddx", "dx", "dX"]:
        #Female
        loc = shape_list.index(s)
        if text_list[loc-1].lower() in ["my", "me", "i"]:
            print(text_list[loc-1])
            print("> Author located! The author is female!")
            continue
        else:
            print(text_list[loc-1])
            print("Not the author")
            continue
    elif s in ["dd", "d"]:
        #Male
        loc = shape_list.index(s)
        if text_list[loc-1].lower() in ["my", "me", "i"]:
            print(text_list[loc-1])
            print("> Author located! The author is male")
            continue
        else:
            print("Not the author")
            continue
    else:
        pass
patent trenchBOT
#

@mighty reef

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

mighty reef
#

For further clarity shape_list is a list of the shapes of the word so for example:
Hello ---> Xxxxx
24 ---> dd
24F ---> ddX

sly steppe
#

I'm not going to help because I don't believe in the idea of pronouns.

mighty reef
#

huh

#

not like he him or anything

#

its just first person pronouns

#

Like I Me My

lone idol
robust fern
#

That's because list.index will look for first appearance of the given element - so if gf/sister/whatever is before the F poster, then you'll always get loc of that first F person.
You should do enumerate

#

<@&831776746206265384> bigot troll

#

!enumerate @mighty reef see this, use the index part of enumerate instead of using list.index

patent trenchBOT
#
The `enumerate` function

Ever find yourself in need of the current iteration number of your for loop? You should use enumerate! Using enumerate, you can turn code that looks like this:

index = 0
for item in my_list:
    print(f"{index}: {item}")
    index += 1

into beautiful, pythonic code:

for index, item in enumerate(my_list):
    print(f"{index}: {item}")

For more information, check out the official docs, or PEP 279.

severe mist
#

!cban 133205620731019264 "Refer to me as a black Mexican e-girl" is an unacceptable insult. Reflect on your behavior.

patent trenchBOT
#

:incoming_envelope: :ok_hand: applied ban to @sly steppe permanently.

thorn laurel
#

!close

patent trenchBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.