2016-07-29 13 views
0

Suchen Sie nach einer Möglichkeit, die folgende String-Liste in Unterliste zu teilen und mit einer For-Schleife zu drucken.Split-String-Liste in Unterliste in Python

[[[u'Book1', None, u'Thriller', u'John C', u'07/12/2012'], 
[u'Book2', u'1', u'Action', u'Tom B', u'07/12/2012'], 
[u'Book3', None, u'Romance', u'Angie P', u'07/12/2012'], 
[u'Book4', None, u'Comedy', u'Tracy N', u'07/12/2012'], 
[u'Book5', None, u'Drama', u'Kumar P', u'07/12/2012'], 
[u'Book6', None, u'Action&Drama', u'Ben J', u'07/12/2012']]] 

Jeder Vorschlag bitte.

+0

Welche Bedingung tun Sie verwenden möchten, es zu teilen? – Suever

+0

basierend auf [u'Book1 ', None,'Thriller', u'John C ', u'07/12/2012'] – phani

+0

Was ist Ihre erwartete Ausgabe? –

Antwort

1

Ihre Frage ist ein bisschen vage! Wenn ich deine Frage richtig verstanden habe, kannst du es so machen:

a = [[[u'Book1', None, u'Thriller', u'John C', u'07/12/2012'], [u'Book2', u'1', u'Action', u'Tom B', u'07/12/2012'], [u'Book3', None, u'Romance', u'Angie P', u'07/12/2012'], [u'Book4', None, u'Comedy', u'Tracy N', u'07/12/2012'], [u'Book5', None, u'Drama', u'Kumar P', u'07/12/2012'], [u'Book6', None, u'Action&Drama', u'Ben J', u'07/12/2012']]] 
for v in a[0]: 
    print(v) 
+0

Danke, es hat funktioniert und tut mir leid für die vage Frage. – phani

2

Suchst du das?

def testString(): 
    input = [[ 
    [u'Book1', None, u'Thriller', u'John C', u'07/12/2012'], 
    [u'Book2', u'1', u'Action', u'Tom B', u'07/12/2012'], 
    [u'Book3', None, u'Romance', u'Angie P', u'07/12/2012'], 
    [u'Book4', None, u'Comedy', u'Tracy N', u'07/12/2012'], 
    [u'Book5', None, u'Drama', u'Kumar P', u'07/12/2012'], 
    [u'Book6', None, u'Action&Drama', u'Ben J', u'07/12/2012'] 
    ]] 
    for subarray in input[0]: 
     print (subarray) 

Dies ist die Ausgabe

['Book1', None, 'Thriller', 'John C', '07/12/2012'] 
['Book2', '1', 'Action', 'Tom B', '07/12/2012'] 
['Book3', None, 'Romance', 'Angie P', '07/12/2012'] 
['Book4', None, 'Comedy', 'Tracy N', '07/12/2012'] 
['Book5', None, 'Drama', 'Kumar P', '07/12/2012'] 
['Book6', None, 'Action&Drama', 'Ben J', '07/12/2012']