Line:

^310003312 ^310005818 

It is obtained from:

  def get_author_id(name): return author_by_id.get(name) for name in authors_a: author_id = get_author_id(name) d = "^3{}".format(author_id) print(d) 

Record rises above each other. Desired total:

 b = ['^310003312', '^310005818'] 

So that later I could turn on the index and get the result. For example:

 print(b[1]) 

Receive:

 ^310005818 

I tried to share, but the line still stands above each other, and not into the line:

 b = b.split(' ') ['^310003312'] ['^310005818'] 

And the index is not possible to apply. Tell me, please, how can I solve this problem?

  • @ 1st Sentinel 31 Year Perl Hist, it would be better if you wrote to me why after the split I cannot turn on the index? - Ireen1985

1 answer 1

After all, there are lines separated by a hyphen \n , so split on it:

 text = """^310003312 ^310005818""" items = text.splitlines() print(items) # ['^310003312', '^310005818'] # Или: items = text.split('\n') print(items) # ['^310003312', '^310005818'] print(items[1]) # ^310005818 

UPD.

 def get_author_id(name): return author_by_id.get(name) items = ["^3{}".format(get_author_id(name)) for name in authors_a] # Или: items = [] for name in authors_a: author_id = get_author_id(name) d = "^3{}".format(author_id) items.append(d) print(items) 

Ps.

Use repr() to see the hidden:

 print(repr(text)) 
  • I'm already with the transfer, and without. Everything twisted. I don't even care that they get on top of each other. I can not turn on the index - that's what's bad! This line is derived from yesterday's formula: d = "^3{}".format(author_id) . Maybe that's the point? - Ireen1985
  • @ Ireen1985, my example did not help you? - gil9red 3:49
  • I know these options. I applied them, but no sense. Added a yesterday's function to the question, from which such a string is obtained. I think that there is a problem in the for loop - Ireen1985
  • @ Ireen1985, added in response in UPD - gil9red
  • just gorgeous !!! Thank you very much!!! Everything is working!!! - Ireen1985