0

Looking for a way to split the following string list into sublist and print using a for loop.

[[[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']]]

Any suggestion please.

4
  • What condition do you want to use to split it? Commented Jul 29, 2016 at 17:02
  • based on [u'Book1', None, u'Thriller', u'John C', u'07/12/2012'] Commented Jul 29, 2016 at 17:06
  • What is your expected output? Commented Jul 29, 2016 at 17:08
  • 1
    You should post what have you tried. Commented Jul 29, 2016 at 17:17

2 Answers 2

2

Are you looking for this?

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)

This is the output

['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']
Sign up to request clarification or add additional context in comments.

Comments

1

Your question is a bit vague! If I understood your question correctly, you can do it like this:

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.