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
>>> 

沒有留言:

張貼留言

ESP32 — MQTT 基本範例

  ESP32 — MQTT 基本範例 介紹 本課程 將 展示WOKWI ESP32 模擬的基本MQTT協定使用。 每兩秒向主題“alex9ufo/outTopic”發布“hello world”。 訂閱主題“alex9ufo/inTopic”,列印收到的所有訊息。 它假設接收到...