(Jun-17-2019, 10:16 AM)noisefloor Wrote: Hi,
@sodmzs: iterating withrange(len(..))
and the index over an iterable is an anti-pattern, don't do it. Python support direct iteration:
>>> one = ['one', 'o', 'n' ,'e'] >>> two = ['two', 't', 'w', 'o'] >>> for item in one: ... for other_item in two: ... print('{} {}'.format(item, other_item)) ... one two one t one w one o o two o t o w o o n two n t n w n o e two e t e w e o >>>But using itertools as shown is the more elegant way anyway.
Regards, noisefloor
Thanks for your reply, but I was looking forward for the other words in the string will stay as it is same. That is in my case, the string was "one and two" Means just the "one" And "two" Will iterate and "and" Word will be in the same position. Since, I want to make it flexible so that in case I would have a string like "two and one and two" Then it can work well with this as well.