Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simplyfy
#3
Itertools is cool to get every combination, or you can also just iterate over the list.

word = "abcde"
twoletter = []
for left in word:
    for right in word:
        if left != right:
            twoletter.append(left + right)
print(twoletter)
# ['ab', 'ac', 'ad', 'ae', 'ba', 'bc', 'bd', 'be', 'ca', 'cb', 'cd', 'ce', 'da', 'db', 'dc', 'de', 'ea', 'eb', 'ec', 'ed']
Reply


Messages In This Thread
Simplyfy - by podge - Apr-30-2017, 04:38 PM
RE: Simplyfy - by buran - Apr-30-2017, 04:50 PM
RE: Simplyfy - by nilamo - Apr-30-2017, 05:11 PM
RE: Simplyfy - by podge - Apr-30-2017, 06:00 PM
RE: Simplyfy - by nilamo - Apr-30-2017, 07:08 PM
RE: Simplyfy - by volcano63 - Apr-30-2017, 07:49 PM
RE: Simplyfy - by nilamo - Apr-30-2017, 08:21 PM
RE: Simplyfy - by volcano63 - Apr-30-2017, 08:30 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020