2018年1月8日 星期一

Python: Check whether a specified value is contained in a group of values

Python: Check whether a specified value is contained in a group of values

Python Basic: Exercise-25 with Solution

Write a Python program to check whether a specified value is contained in a group of values.
Test Data:
3 -> [1, 5, 8, 3] : True
-1 -> [1, 5, 8, 3] : False
Sample Solution:-
def is_group_member(group_data, n):
    for value in group_data:
        if n == value:
            return True
    return False
print(is_group_member([1, 5, 8, 3], 3))
print(is_group_member([5, 8, 3], -1))
=========== RESTART: F:/Python_APSC/py-ex-basic-25.py ========
True
False
>>> 

沒有留言:

張貼留言

Python Modbus 控制 ADAM-6050 18-ch Isolated Digital I/O Module

Python Modbus 控制  ADAM-6050 18-ch Isolated Digital I/O Module import tkinter as tk from tkinter import messagebox from pymodbus.client impor...