#๐ How to remove a text that is present in a string?
39 messages ยท Page 1 of 1 (latest)
@lyric hollow
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.
but it does not seem to work
text = td.css('div.narrow ::text').getall() [list]
is_replying_to = td.css('div.narrow blockquote *::text').getall() if td.css('div.narrow blockquote ::text').getall() else '' [list]```
this is not how you write python code
I put list
so you know what the function returns
can u not do that
im getting errors when i paste it
fixed?
the text box was too small so i didnt see the the new line
no
changed the code above
found a solution
text = td.css('div.narrow ::text').getall()
is_replying_to = td.css('div.narrow blockquote *::text').getall() if td.css('div.narrow blockquote ::text').getall() else ''
filtered_text = [item for item in text if item not in is_replying_to]
item for item in text if item not in is_replying_to
what does that even mean(sorry to poke in bw)
what does for keyword signify here
i mean i know we can do like
print("hi" if a > 4 else "bye")
i was not aware we could use for too
it's a "list comprehension" syntax
In short , what is that
a single line for loop
it's like :
for item in text:
if item not in is_replying_to:
filtered_text.append(item)```
to make it shorter, I used a list comprehension
this is equivalent to filtered_text = [item for item in text if item not in is_replying_to]
??
yes
feels good to know something new
thank you !!
yw
the if is also optional
!e
data = ['apples', 'oranges', 'bananas']
print([i.upper() for i in data])
:white_check_mark: Your 3.12 eval job has completed with return code 0.
['APPLES', 'ORANGES', 'BANANAS']
yeah i figured ๐ค < 3
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.