python find second occurrence in string code example
Example 1: python replace first occurrence in string
# string replace() function perfectly solves this problem:
# string.replace(s, old, new[, maxreplace])
# Return a copy of string s with all occurrences of substring old replaced
# by new. If the optional argument maxreplace is given, the first maxreplace
# occurrences are replaced.
>>> u'longlongTESTstringTEST'.replace('TEST', '?', 1)
u'longlong?stringTEST'
Example 2: python find first occurrence in list
#iterate through list
for item in yourlist:
#if item is equal to a value
if item == 'value':
#store the item in a variable
yourvar = item
#break out of loop
break
Example 3: python find second occurrence in string
s = string.find(substring, string.find(substring) + 1)