Knowee
Questions
Features
Study Tools

The function array123(list1) returns True if the sequence of numbers 1, 2, 3 appears in the list somewhere.Examplelist1 = [1, 1, 2, 3, 1]Expected output: True

Question

The function array123(list1) returns True if the sequence of numbers 1, 2, 3 appears in the list somewhere.

Example:

list1 = [1, 1, 2, 3, 1]  

Expected output:
True

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python function that implements the logic you described:

def array123(list1):
    # Convert all elements in the list to string
    list1 = [str(i) for i in list1]
    # Join all elements in the list to form a string
    str1 = ''.join(list1)
    # Check if '123' is in the string
    if '123' in str1:
        return True
    else:
        return False

# Test the function
list1 = [1, 1, 2, 3, 1]
print(array123(list1))  # Expected output: True

This function works by first converting all elements in the list to strings, then joining them together to form a single string. It then checks if the string '123' is in this string. If it is, the function returns True, otherwise it returns False.

This problem has been solved

Similar Questions

Which of the following would give an error?list1=[]list1=[]*3list1=[2,8,7]None of the above

Which of the following statement will create list?L1=list( )L1=[1,2,3,4]Both of the above

Which example below is declaring an array in Python?Array == 1, 2, 3[1, 2, 3]I don't know

What does the range(3) function return?Points:1[0, 1, 2][3, 2, 1, 0][0, 1, 2, 3]I don't know[1, 2, 3]

What is the output of the following?a = array([1,2,3,'string'])print(a)Select one:ErrorNone of them1 2 3 string1 2 3 “string”

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.