Y
Y
YraganTron2014-01-18 02:41:47
Python
YraganTron, 2014-01-18 02:41:47

Inverse join function

There is a code:

from random import randrange as rnd

a = [rnd(10) for x in range(50)]

print a

print ''.join(map(str,a))

a = ''.join(map(str,a))
c = []
print a.split('0')
c = a.split('0')

if len(c) > 2:
  b = []
  b.append(c[0])
  b.append(c[-1])
  print b
if len(c) == 2:
  q = []
  q.append(c[-1])
  print q
if len(c) < 2:
  print a

The task is to delete part of the list between 0 and 0. If 0 is one, then delete part of the list before this 0. If 0 is not present, then do not change anything. My code is rather some kind of perversion and the solution here is much simpler, but still.
At the output, I get a list processed by the join function. Interested in how to bring the list to its original form when the task is already completed.
Those. the start list looks like this [1,5,2,6,7.....8]
and my end list currently looks like this [ '123554662', '34531'].

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DuD, 2014-01-18
@YraganTron

Try to use this function, it is far from ideal, but it will solve your problem.

def mergelist(lst):
    all=''
    for item in lst:
        all += str(item)
    return list(all)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question