0

I want to join the elements in the list as 1-9,2-10,3-11,4-12,5-13,...... I have tried for small number of lists.But for large number of list,I don't know how to do this.

#!/usr/bin/python
seq1 = ['A','B','C','D','E','F','G,','H','I','J']
seq2 = seq1[0]+seq1[1]+seq1[2]+seq1[3]+seq1[4]+seq1[5]+seq1[6]+seq1[7]+
        seq1[8]
seq3 = seq1[1]+seq1[2]+seq1[3]+seq1[4]+seq1[5]+seq1[6]+seq1[7]+seq1[8]+
         seq1[9]
print seq2,seq3
Aishwarya
  • 69
  • 5

3 Answers3

0

This is slicing:

Code:

seq = 'abcdefghij'
seqs = [seq[i:i+5] for i in range(4)]
print(seqs)

Results:

['abcde', 'bcdef', 'cdefg', 'defgh']
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
0

You can try:

seq1 = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P']

for index,number in enumerate(seq1):
    if index <=len(seq1)-9:
        print "".join(seq1[index:index+9])

Output:

ABCDEFGHI
BCDEFGHIJ
CDEFGHIJK
DEFGHIJKL
EFGHIJKLM
FGHIJKLMN
GHIJKLMNO
HIJKLMNOP
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
0
seq1 = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N']

length = 9
for i in range(0,len(seq1)-length+1):
    seq2 = ''.join(seq1[i:i+length])
    print(seq2)

Where length is the length of sequences you want to construct.

Mario Camilleri
  • 1,457
  • 11
  • 24