Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
join string lists
#6
I'm curious to hear from some of the more experienced coders on the forum what they think is the best way to do this. I understand that it's generally considered desirable to avoid using range(len(sequence)), but I'm having a hard time doing so without adding lines of code or checks I wouldn't need otherwise.

Here is what I came up with:
l = ['a', 'b', 'c', 'd']
newl = []

for i in range(len(l) -1):
    newl.append(''.join(l[i] + l[i+1]))

print(newl)
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,466 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,866 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  The difference between os.path.join( and os.sep.join( Pedroski55 2 9,519 Nov-17-2020, 08:38 AM
Last Post: Pedroski55
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,426 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Partial convertion string to int in lists satellite89 6 3,467 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,317 Mar-20-2019, 08:01 PM
Last Post: stillsen
  SQL select join operation in python(Select.. join) pradeepkumarbe 1 2,263 Feb-14-2019, 08:34 PM
Last Post: woooee
  Sorting list of lists with string and int Otbredbaron 6 4,242 May-07-2018, 06:04 AM
Last Post: buran
  How to create a long string by concatenating two lists nikhilkumar 11 7,583 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