python 3.x - Returning True if a sequence appears in a list -


i need write function takes list of ints nums , returns true if sequence 1, 2, 3, .. appears in list somewhere.

my approach:

def list123(nums):     num = ""     in nums:         num +=     if "1,2,3" in num:         return true     else:         return false 

it fails work indicating: builtins.typeerror: can't convert 'int' object str implicitly

i know if there more simpler way, rather converting list string i've done.

you error on num += i, because trying add 1 "". instead, try following:

def list123(nums):     desired = [1, 2, 3]     if str(desired)[1:-1] in str(nums):         return true     return false 

>>> list123([1, 2, 3, 4, 5]) true >>> list123([1, 2, 4, 3, 5]) false >>> list123([5, 1, 2, 7, 3, 1, 2, 3]) true >>>