Basic programming question on find() function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lel7lel7
    New Member
    • Mar 2010
    • 12

    Basic programming question on find() function

    I am familiar with the notation
    >>>dna = ....
    >>>Ecori = "ATGATG"... .
    >>>find(dna, Ecori)
    >>>find(dna,Eco ri, 2)

    My question is how to i find the second undefined base 'n'
    ie.
    >>>seq = 'ATGATGnATGnATG '
    >>>find(seq, 'n')
    6
    >>>find(seq, 'n', 2)
    6 Does not work - Should say 10
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Your argument '2' is the starting index position, not the second occurrence. Example:
    Code:
    >>> import string
    >>> string.find('ATGATGnATGnATG', 'n', 2)
    6
    >>> string.find('ATGATGnATGnATG', 'n', 7)
    10
    >>>
    The string module has been deprecated for a while now. You should use str object methods instead.
    Code:
    >>> 'ATGATGnATGnATG'.find('n', 2)
    6
    >>> 'ATGATGnATGnATG'.find('n', 7)
    10
    >>>

    Comment

    • lel7lel7
      New Member
      • Mar 2010
      • 12

      #3
      Thanks so much - your really helpful :)

      Comment

      Working...