Program in Python to find the presence of reverse of an element in a collection.

Posted by Rajnilari2015 under Python category on | Points: 40 | Views : 152
Suppose we have a colleciton as {78,92,44,63,71,97} and an element 29. We need to find if the reverse of 29 i.e. 92 is present in the collection. The below program will do so

from System import *
from System.Collections.Generic import *
from System.Linq import *

class Program(object):
def Main(args):
intCollection = List[int](78, 92, 44, 63, 71, 97)
element = 29
reverseElement = Convert.ToInt32(str.Join("", element.ToString().Reverse()))
Console.Write("Element found in the collection" if intCollection.IndexOf(reverseElement) != -1 else "Element not found in the collection")

Main = staticmethod(Main)

Element found in the collection

Comments or Responses

Login to post response