#๐Ÿ”’ How to remove a text that is present in a string?

39 messages ยท Page 1 of 1 (latest)

lyric hollow
#
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``` 
I have tried :
```py
text = ' '.join(text)
text = text.replace(' '.join(is_replying_to), ' ')```
past shuttleBOT
#

@lyric hollow

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.

lyric hollow
#

but it does not seem to work

elder maple
#
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
lyric hollow
#

so you know what the function returns

empty crown
#

can u not do that

elder maple
#

im getting errors when i paste it

lyric hollow
#

ahh

#

changed it

elder maple
#

oh nvm

#

i made a mistakr

empty crown
elder maple
#

the text box was too small so i didnt see the the new line

lyric hollow
#

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]
agile sable
#

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

willow monolith
agile sable
willow monolith
lyric hollow
#
for item in text:
  if item not in is_replying_to:
     filtered_text.append(item)```
#

to make it shorter, I used a list comprehension

agile sable
#

??

agile sable
#

feels good to know something new
thank you !!

willow monolith
#

!e

data = ['apples', 'oranges', 'bananas']
print([i.upper() for i in data])
past shuttleBOT
agile sable
#

yeah i figured ๐Ÿ˜ค < 3

past shuttleBOT
#
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.