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?
Operator. countOf() is used for counting the number of occurrences of b in a. It counts the number of occurrences of value. It returns the Count of a number of occurrences of value.
Python has got in-built method – len() to find the size of the list i.e. the length of the list. The len() method accepts an iterable as an argument and it counts and returns the number of elements present in the list.
There is a built-in function called len() for getting the total number of items in a list, tuple, arrays, dictionary, etc. The len() method takes an argument where you may provide a list and it returns the length of the given list.
Use the len()
function on it:
if len(appended_data) == 1:
Short demo:
>>> len([])
0
>>> len([1])
1
>>> len([1, 2])
2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With