Python Forum
search for a part of strinf from list in another list !
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
search for a part of strinf from list in another list !
#4
(Oct-29-2018, 07:19 AM)evilcode1 Wrote: can u explain please what is this line do ( if re.search('|'.join(lst_find), item): )
>>> lst_find = ["Facebook" , "gmail" , "Yahoo"]
>>> '|'.join(lst_find)
'Facebook|gmail|Yahoo'
In regex | is or,so it will match Facebook or gmail or Yahoo.
>>> import re
>>> 
>>> s = 'hello gmail from Yahoo.This is Facebook.'
>>> re.findall(r'Facebook|gmail|Yahoo', s)
['gmail', 'Yahoo', 'Facebook']
Quote:and why i should use python 3 ?
Python 2 is end of life in a little over a year.
Python 3 is now 10-year old and it fix a lot mistakes that Python 2 had.
Python 2 support is dropped in Django,IPython...ect.
The scientific stack will start drop Python 2 in 2019,like Pandas,Numpy,Matplotlib...ect.

There is lot features that only work in Python 3 Wink
>>> s = 'cool'
>>> p = 'Python'
>>> print(f'There is lot of {s} features that only {p} {2 * 1.8}--> has,like <{f:^15}>')
There is lot of cool features that only Python 3.6--> has,like <   f-string    >
Reply


Messages In This Thread
RE: search for a part of strinf from list in another list ! - by snippsat - Oct-29-2018, 12:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] list of list with one or more empty one paul18fr 5 2,415 Oct-04-2023, 09:08 AM
Last Post: jeffreyteague
  convert a list of string+bytes into a list of strings (python 3) pacscaloupsu 4 10,879 Mar-17-2020, 07:21 AM
Last Post: markfilan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020