-6

Hi i have a lists like this

['ID 1d6b:0002']
['ID 1d6b:0002']
['ID 1d6b:0001']
['ID 1d6b:0001']
['ID 1d6b:0001']
['ID 1d6b:0001']
['ID 1d6b:0001']
['ID 0b38:0010']
['ID 093a:2510']

I want this to one list.Please help me out with this

user2470026
  • 157
  • 1
  • 7

1 Answers1

2

You can do:

old_list = [
['ID 1d6b:0002'],
['ID 1d6b:0002'],
['ID 1d6b:0001'],
['ID 1d6b:0001'],
['ID 1d6b:0001'],
['ID 1d6b:0001'],
['ID 1d6b:0001'],
['ID 0b38:0010'],
['ID 093a:2510']]


new_list = [x[0] for x in old_list]

This uses list comprehension to create a new list that contains the first elements ([0]) all on the lists in the old list.

Hope that helps.

sshashank124
  • 31,495
  • 9
  • 67
  • 76
  • Please provide some details to your answer like what new_list = [x[0] for x in old_list] is doing. I assume the OP can't understand this as per the level of his/her question. :) – ρss Apr 02 '14 at 07:32