Dear Group,
I am trying the following code line:

def try2(n):
	a1=raw_input("PRINT A STRING:")
	a2=a1.split()
	a3="God Godess Heaven Sky"
	for x in a2:
		a4=a3.find(x)
		if a4>-1:
			a5=a3[a4]
			print a5
		elif a4<0:
			a6=x
			print "It is not found"
			print a6
		else:
			print "Error"
	s=a5+" "+a6
	print s

Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its values not the last ones. Can you suggest me any help? Am I missing any minor point?
Best Regards,
Subhabrata.

Recommended Answers

All 2 Replies

Before your for loop you should initialize a5 and a6 as ''. Then within your loop instead of a5 = or a6 = you should use += to concatenate.

You can also convert a1 and a3 to a set and use set intersection and difference.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.