Python Oppe Practice Question 2 | Python code to count 'hostile pairs' | Oppe 1 revision python

preview_player
Показать описание
Join this channel to get access to perks:

In this lecture we will write python code to check hostile pairs. We will look into what are hostile pairs, develop logic to solve the question, write the code and look at important tips. This also serves as python oppe1practice question 1

BIO🧑‍🦱
Hello everyone👋,
I am diploma student of @IITMadrasBSDegreeProgramme . I hope my videos will help you.

Additional Links

Chapters
00:00 - Introduction
00:26 - Understand Qn
02:24 - Develop Logic
05:17 - Write Code
08:33 - Check Results
09:13 - Homework (answer with gist)
09:38 - Contact & Thanks

Kindly practice similar type of questions. Also make sure to focus on how I devise logic, not the code. Thanks, and happy learning.

Hashtags
#iitmadras #pythonprogramming #pythonexercises #exampreparation #devloperhs
Рекомендации по теме
Комментарии
Автор

All codes available here!

Starting today, i will not be sharing video related updates in most groups.

If you want to get notified, kindly subscribe to channel and press that bell 🔔 icon beside the channel, to get notified.

Thanks.

devloper_hs
Автор

Def n_hostile(L):
hostile_pairs = 0
n = len(L)
for i in range(n):
for j in range(i+1):
if not set(str(L[i])) & set(str(L[j])):
hostile_pairs += 1
return hostile_pairs

vishnu_kumar_jha
Автор

def hostile_pair(L):
hostile=0
n=len(L)
for i in range(n):
for j in range(i+1, n):
if not set(str(L[i])) & set(str(L[j])):
hostile+=1
print(hostile)

PRATHAMGUPTA-ew
Автор

import random
l=[]
for i in range(6):
l.append(random.randint(100, 999))

def word_comp(a, b):
flag=1
xa, xb = sorted(str(a)), sorted(str(b))
for letter in xa:
if letter in xb:
flag = 0
break
if flag ==1 :
return 1
else:
return 0


def hostile_chekcer(l):
count, pl = 0, []
for i in range(len(l)):
for j in range(i+1, len(l)):
if word_comp(l[i], l[j])==1:
count+=1
pl.append(str(l[i])+' - '+str(l[j]))

print(f' The Count Is : {count} and The Pairs Are : {pl}')

hostile_chekcer(l)

ayaanahmad
visit shbcf.ru