8

I've got an array (list) that I want to check if it's size is equal to 1, if it is then it needs to append a new like as shown.

## If appended data = 1 then append the new line:
if appended_data == 1:
    appeneded_data.append("") ## Add a new line if appended data has a size of 1

Should be a fairly simple thing but I can't work it out :S

Any ideas?

Ryflex
  • 5,005
  • 24
  • 70
  • 141
  • 1
    did you even google? http://stackoverflow.com/questions/1712227/get-the-size-of-a-list-in-python – mrKelley Jun 19 '13 at 22:01
  • https://www.google.co.in/search?q=how+to+get+length+of+a+list+in+python, typing a simple query on google could've solved your problem in seconds. – Ashwini Chaudhary Jun 19 '13 at 22:03
  • Don't even need Google: http://stackoverflow.com/search?q=get+list+size+python – msw Jun 19 '13 at 22:07
  • Yes, I googled but my question was to precise so it yielded no results matching my needs. – Ryflex Jun 19 '13 at 23:24

1 Answers1

13

Use the len() function on it:

if len(appended_data) == 1:

Short demo:

>>> len([])
0
>>> len([1])
1
>>> len([1, 2])
2
Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187