Q:

# Check if two sets have any elements in common. If yes, display the common elements using python programming

### Check if two sets have any elements in common. If yes, display the common elements

Given:

``````set1 = {10, 20, 30, 40, 50}
set2 = {60, 70, 80, 90, 10}``````

Expected output:

```Two sets have items in common
{10}```

Hint:

• Use the `isdisjoint()` method check if sets has a common elements
• If above condition is true then use the `intersection()` method to display common elements

Solution:

``````set1 = {10, 20, 30, 40, 50}
set2 = {60, 70, 80, 90, 10}

if set1.isdisjoint(set2):
print("Two sets have no items in common")
else:
print("Two sets have items in common")
print(set1.intersection(set2))``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.7627938,"math_prob":0.9459339,"size":545,"snap":"2023-40-2023-50","text_gpt3_token_len":167,"char_repetition_ratio":0.13678373,"word_repetition_ratio":0.43010753,"special_character_ratio":0.35412845,"punctuation_ratio":0.20661157,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98408806,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-03T12:01:39Z\",\"WARC-Record-ID\":\"<urn:uuid:6e48ca2b-dcd5-4f24-8ef5-b140ff308bba>\",\"Content-Length\":\"55671\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9bb37fba-7840-4626-893b-f5228fc228e7>\",\"WARC-Concurrent-To\":\"<urn:uuid:3261a35b-7a06-40a8-8035-44e2883d1097>\",\"WARC-IP-Address\":\"88.202.183.220\",\"WARC-Target-URI\":\"https://nerdutella.com/q1116-Check-if-two-sets-have-any-elements-in-common-If-yes-display-the-common-elements-using-python-programming\",\"WARC-Payload-Digest\":\"sha1:MA6M4P6IKOUOF7Y4DWF6XIADW23UP6AB\",\"WARC-Block-Digest\":\"sha1:ECEEJ7IIVUZNRKCCE7T3HFZSSVVMTBNR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100499.43_warc_CC-MAIN-20231203094028-20231203124028-00093.warc.gz\"}"}