Question on Joining of list

SUBHABRATA subhabrata.iisc at hotmail.com
Fri Jul 18 12:00:41 CEST 2008


Sorry if I didn't say that.
The input is a string "Petrol Helium Heaven Sky"
Now, in a3 it is "God Goddess Heaven Sky" is there,
it is matching Heaven and Sky but not Petrol and Helium as they are
not in a3.
Now, as per the code it is giving me an output "S" of "Sky" and
"Helium"
But I was looking for an output of  "H S Petrol Helium" and not "S
Helium" meaning all the values of a5 and a6 will be concatenated in s.
Best Regards,
Subhabrata..

Marc 'BlackJack' Rintsch wrote:
> On Fri, 18 Jul 2008 01:31:59 -0700, SUBHABRATA wrote:
>
> > 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?
>
> Maybe you should describe what the input looks like and what output you
> want to have and how the input and output are connected.  In words, not in
> not very clear code with "numbered names".  That's a silly idea and makes
> understanding the code very hard.  Please use meaningful names!
>
> Ciao,
> 	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list