e.g.
a = 'abc123def'
b = 'abcdef'
I want a function which can judge whether b in a.
contains(a,b)=True
p.s. gap is also allowed in the represention of b, e.g.
b='abc_def'
but regular expressions are not allowed.
e.g.
a = 'abc123def'
b = 'abcdef'
I want a function which can judge whether b in a.
contains(a,b)=True
p.s. gap is also allowed in the represention of b, e.g.
b='abc_def'
but regular expressions are not allowed.
 
    
    If what you want to do is to check whether b is a subsequence of a, you can write:
def contains(a, b):
    n, m = len(a), len(b)
    j = 0
    for i in range(n):
        if j < m and a[i] == b[j]:
            j += 1
    return j == m
 
    
    Try using list comprehension:
def contains(main_string, sub_string):
    return all([i in main_string for i in sub_string])
NOTE: 'all' is a builtin function which takes an iterable of booleans and returns try if all are True.
 
    
     
    
    def new_contained(a,b):
   boo = False
   c = [c for c in a]
   d =  [i for i in b]
   if len(c)<=len(d):
     for i in c:
        if i in d:
          boo = True
   return boo  
