the input is [120, [10, 20, 30]]
i split the balance using this code

def checkio(data):
    balance=[int(x) for x in data[0:1]]

but when i split it the withdrawal section looks like [[10,20,30]]
which hinders the loops im going to do.
I want it to have single brackets like so: [10,20,30]
how do i go about doing this

5 Years
Discussion Span
Last Post by toniann.midori

data[1:2] is a list splice. It returns the sublist of data that goes from index 1 (inclusive) to index 2 (exclusive). So basically it returns a list that contains the element at index 1 and nothing else. If all you want is the element at index 1 without a list wrapped around it, just use normal indexing:

withdrawal = data[1]

It also seems strange to me that you use a list comprehension on a 1-element list to get the balance. I would just do balance = int(data[0]) if I were you. If there's a good reason why balance should be a 1-element list, you could also do balance = [ int(data[0]) ], but I don't see what that reason could be.


The list show only integer,so why convert at all.

>>> lst = [120, [10, 20, 30]]
>>> lst[0]
>>> lst[1]
[10, 20, 30]
>>> type(lst[0])
<type 'int'>

>>> balance, withdrawal = lst[0], lst[1]
>>> balance
>>> withdrawal
[10, 20, 30]

Edited by snippsat

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.