Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
join string lists
#10
Assuming that if you only pass a list with one item it returns an empty list.
from string import ascii_uppercase


def adjacent_list(iterabe):
    stored_character = None
    for character in iterabe:
        if stored_character:
            yield ''.join((stored_character, character))
        stored_character = character


for index in range(1, 27):
    letters = (ascii_uppercase[:index])
    print(list(adjacent_list(letters)))
Output:
[] ['AB'] ['AB', 'BC'] ['AB', 'BC', 'CD'] ['AB', 'BC', 'CD', 'DE'] ['AB', 'BC', 'CD', 'DE', 'EF'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP', 'PQ'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP', 'PQ', 'QR'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP', 'PQ', 'QR', 'RS'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP', 'PQ', 'QR', 'RS', 'ST'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP', 'PQ', 'QR', 'RS', 'ST', 'TU'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP', 'PQ', 'QR', 'RS', 'ST', 'TU', 'UV'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP', 'PQ', 'QR', 'RS', 'ST', 'TU', 'UV', 'VW'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP', 'PQ', 'QR', 'RS', 'ST', 'TU', 'UV', 'VW', 'WX'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP', 'PQ', 'QR', 'RS', 'ST', 'TU', 'UV', 'VW', 'WX', 'XY'] ['AB', 'BC', 'CD', 'DE', 'EF', 'FG', 'GH', 'HI', 'IJ', 'JK', 'KL', 'LM', 'MN', 'NO', 'OP', 'PQ', 'QR', 'RS', 'ST', 'TU', 'UV', 'VW', 'WX', 'XY', 'YZ']
Reply


Messages In This Thread
join string lists - by redminote4dd - Jun-11-2020, 01:37 PM
RE: join string lists - by menator01 - Jun-11-2020, 02:06 PM
RE: join string lists - by DPaul - Jun-11-2020, 02:06 PM
RE: join string lists - by redminote4dd - Jun-11-2020, 02:15 PM
RE: join string lists - by menator01 - Jun-11-2020, 02:17 PM
RE: join string lists - by GOTO10 - Jun-11-2020, 02:33 PM
RE: join string lists - by redminote4dd - Jun-11-2020, 02:56 PM
RE: join string lists - by perfringo - Jun-11-2020, 02:42 PM
RE: join string lists - by pyzyx3qwerty - Jun-11-2020, 04:41 PM
RE: join string lists - by Yoriz - Jun-11-2020, 07:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ''.join and start:stop:step notation for lists ringgeest11 2 2,433 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,807 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  The difference between os.path.join( and os.sep.join( Pedroski55 2 9,456 Nov-17-2020, 08:38 AM
Last Post: Pedroski55
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,373 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Partial convertion string to int in lists satellite89 6 3,434 Apr-22-2019, 08:50 PM
Last Post: Yoriz
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,275 Mar-20-2019, 08:01 PM
Last Post: stillsen
  SQL select join operation in python(Select.. join) pradeepkumarbe 1 2,235 Feb-14-2019, 08:34 PM
Last Post: woooee
  Sorting list of lists with string and int Otbredbaron 6 4,178 May-07-2018, 06:04 AM
Last Post: buran
  How to create a long string by concatenating two lists nikhilkumar 11 7,539 Jul-12-2017, 05:36 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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