{"id":9549,"date":"2021-09-30T12:00:04","date_gmt":"2021-09-30T06:30:04","guid":{"rendered":"https:\/\/python-programs.com\/?p=9549"},"modified":"2021-11-22T18:35:27","modified_gmt":"2021-11-22T13:05:27","slug":"python-program-to-print-all-permutations-of-a-string-in-lexicographic-order-without-recursion","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-all-permutations-of-a-string-in-lexicographic-order-without-recursion\/","title":{"rendered":"Python Program to Print All Permutations of a String in Lexicographic Order without Recursion"},"content":{"rendered":"

Strings in Python:<\/strong><\/p>\n

Strings are simple text in programming, which might be individual letters, words, phrases, or whole sentences. Python strings have powerful text-processing capabilities, such as searching and replacing characters, cutting characters, and changing case. Empty strings are written as two quotations separated by a space. Single or double quotation marks may be used. Three quote characters can be used to easily build multi-line strings.<\/p>\n

Given a string ,the task is to print all the permutations of the given string in lexicographic order without using recursion in Python.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given string ='hug'<\/pre>\n

Output:<\/strong><\/p>\n

printing all [ hug ] permutations :\r\nhug\r\nugh\r\nuhg\r\nghu\r\nguh\r\nhgu<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given string ='tork'<\/pre>\n

Output:<\/strong><\/p>\n

printing all [ tork ] permutations :\r\ntork\r\ntrko\r\ntrok\r\nkort\r\nkotr\r\nkrot\r\nkrto\r\nktor\r\nktro\r\nokrt\r\noktr\r\norkt\r\nortk\r\notkr\r\notrk\r\nrkot\r\nrkto\r\nrokt\r\nrotk\r\nrtko\r\nrtok\r\ntkor\r\ntkro\r\ntokr<\/pre>\n

Program to Print All Permutations of a String in Lexicographic Order without Recursion<\/h2>\n

Below are the ways to Print All string permutations without recursion in lexicographic order:<\/p>\n