Home > Software engineering >  extracting from a list
extracting from a list

Time:09-17

how can I extract each value from the list?

[['f', 'Mina', 'C'], ['f', 'Sara', 'java'], ['m', 'Omid', 'C  '], ['m', 'Hooman', 'python']]

I want the output be like this

f Mina C
f Sara java
m Omid C  
m Hooman python

CodePudding user response:

Here you go! If you found this to solve your question, please accept the solution.

list_val =[['f', 'Mina', 'C'], ['f', 'Sara', 'java'], ['m', 'Omid', 'C  '], ['m', 
'Hooman', 'python']]

for j in  (list_val):
    print (j[0],j[1],j[2])

enter image description here

CodePudding user response:

The following code is one method of getting the result you want.

list = ['f', 'Mina', 'C'], ['f', 'Sara', 'java'], ['m', 'Omid', 'C  '], 
['m', 'Hooman', 'python']


for i in list:
  print(i) 

The output of the code will be:

['f', 'Mina', 'C']
['f', 'Sara', 'java']
['m', 'Omid', 'C  ']
['m', 'Hooman', 'python']

Hope I helped and happy coding!

CodePudding user response:

You can use this:

name_list =[['f', 'Mina', 'C'], ['f', 'Sara', 'java'], ['m', 'Omid', 'C  '], ['m', 
'Hooman', 'python']]
for names in name_list:
    print(names)

remember to assign name_list variable for list

  • Related