Answer to Question #197009 in Python for Hari nadh babu

Question #197009

Non-Adjacent Combinations of Two Words


Write a Python Program of Non-Adjacent Combinations of Two Words


The above link contains Question and test cases

https://drive.google.com/file/d/1BAzikXzPal2JOSNLSXuxx2lASwEb-cpF/view?usp=sharing


We need all test cases can be came when code was run. I want exact outputs for all test cases

1
Expert's answer
2021-05-23T08:05:24-0400
def non_adjacent(words:str):


	words_list = words.split()
	result = []
	l = len(words_list)
	for i in range(l-2):
		for j in range(i+2, l):
			tmp1 = words_list[i]
			tmp2 = words_list[j]
			index_tmp1 = [k for k in range(l) if words_list[k]==tmp1]
			index_tmp2 = [m for m in range(l) if words_list[m]==tmp2]
			not_adj = True
			for el1 in index_tmp1:
				for el2 in index_tmp2:
					if abs(el1 - el2) == 1:
						not_adj = False
			tmp = sorted([tmp1, tmp2])
			if tmp not in result and not_adj:
				result.append(tmp)
	for el in sorted(result):
		print(*el)




while True:
	non_adjacent(input())

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS