Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

How can I shorten this loop in python?

(0) ShareShare
ReportReport
Posted on by 10

I'm working on a "word generator" But I have a problem. Sometimes it creates unwanted words. I would like to remove them but not to heavy the loop.

I have to do like the example in the code with the whole alphabet. There would be nothing wrong with it that much, but there are a few other problems that I would have dealt with if only I knew how to cut it short.

Link

# alph = "abcdefghijklmnopqrstuvwyzxÄ…"

my_var = ["abc", "aabc", "cbd", "ccbd", "qwe", "qqwe"]
my_var2 = []


def removeDup():
for x in my_var:
if x.find("aa") == -1 and x.find("cc") == -1 and x.find("qq") == -1:
my_var2.append(x)
print(my_var2)

removeDup()

My idea is dynamic variables, but I can't make one loop in the other without creating chaos I tried something like the one in the picture, but I can only take out words with repeated letters

  • RE: How can I shorten this loop in python?

    Hi ZainUlAbdeen,

    The output of your code is ['abc', 'cbd', 'qwe'], which is not you want to achieve?

    If so, please tell us what you want to get, a string result 'abcdqwe'?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans