Python searching patterns in lists of strings -


i have list of strings following in python:

         ss = ['t', 'q', 't', 'd', 'q', 'd', 'd', 'q', 't', 'd'] 

is there anyway check how many ts directly followed d, in case, there 2 ts (second , last t) meet requirement.

i tried not working though, advice? thx!

            if ['t','q'] in ss:                  print ("yes") 

you iteratively checking if next character d , implementing sort of counter. (probably) tersest, although maybe not best way.

ss = ['t', 'q', 't', 'd', 'q', 'd', 'd', 'q', 't', 'd'] print("".join(ss).count("td")) 

result:

2 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -