comparing string in arrays
|
|||
|
Rank: Unregistered
|
Hi everybody!
I have a string array, i.e. ['name1', 'name2'] I want to compare each of the elements of the string with another string (i.e. 'name2') to see if there is in the array the string I was searching. Merci!! |
||
|
|||
|
|||
|
Rank: ? (1)
Member #: 27511 |
Hey Did you get any reply on how to compare string in arrays ? I need this tip now. I have a string array, i.e. ['name1', 'name2'] I want to compare each of the elements of the string with another string (i.e. 'name2') to see if there is in the array the string I was searching. |
||
|
|||
|
|||
|
Rank: ? (4)
Member #: 27845 |
Hey,
This is actually pretty straight forward: ============================================ """Program for playing around with the regular expressions. How to use from command line: >>> import revise_res >>> regex_obj = revise_res.revise_reg_exp() >>> regex_obj.compare_strings("sEsHa" sesha exist in the string compare list >>> regex_obj.compare_strings("sEsa" sEsa doesnt exist in the string compare list """ __author__ = "Sesha Srinivas(sesha_srinivas@yahoo.com)" __revision__ = "$Revision:1.0 $" __updates__ = "Added new functionality to run the code from command line" __date__ = "2006/06/21" import re import sys import os class revise_reg_exp: """Class with regular expressions """ # values to be changed to # Define all your xml elements here string_compare_list = {"sesha":"Sesha", "srinivas":"Srinivas" } def compare_strings(self, search_string): """Gets the search string and searches if there is a pattern match Returns the STRING found or a message indicating string not found """ found = False for elements in self.string_compare_list or found == True: if elements.upper() == search_string.upper(): print "%s exist in the string compare list" %(elements) found = True if found == False: print "%s doesnt exist in the string compare list" %(search_string) =============================================== |
||
|
Please login or register to post a reply.