File tree 1 file changed +13
-6
lines changed 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -159,19 +159,26 @@ def flatten(iterables):
159
159
else :
160
160
yield i
161
161
162
- def commonprefix (* instrings ):
162
+ def commonprefix (iterable , ignore_case = False ):
163
163
""" Common prefix of input strings using OrderedDict
164
164
165
- >>> commonprefix('Python','Pythonista')
165
+ >>> commonprefix([ 'Python','Pythonista'] )
166
166
'Python'
167
- >>> commonprefix('Persia','Person','Perl','Perlite')
167
+ >>> commonprefix(( 'Persia','Person','Perl','Perlite') )
168
168
'Per'
169
- >>> commonprefix('Batman', 'Battleship','Batista','Bat')
170
- 'Bat'
171
-
169
+ >>> commonprefix(['rambo', 'Rambo'], ignore_case=True)
170
+ 'rambo'
172
171
"""
173
172
174
173
d = collections .OrderedDict ()
174
+
175
+ if isinstance (iterable , collections .Iterable ):
176
+ instrings = iterable
177
+ else :
178
+ raise Exception ("Only Iterables are allowed as an Input" )
179
+
180
+ # adjusting input strings according to the ignore_case option
181
+ instrings = map (str .lower , instrings ) if ignore_case else instrings
175
182
176
183
for instring in instrings :
177
184
for idx ,char in enumerate (instring ):
You can’t perform that action at this time.
0 commit comments