Handling the exception is the way to go:
try:
gotdata = dlist[1]
except IndexError:
gotdata="null"
Of course you could also check the len()
of dlist
; but handling the exception is more intuitive.
More Related Contents:
- How to iterate through two lists in parallel?
- Transpose/Unzip Function (inverse of zip)?
- Are lists thread-safe?
- Python List vs. Array – when to use?
- How can I iterate through two lists in parallel?
- Getting a list of values from a list of dicts
- Pairs from single list
- Splitting a list based on a delimiter word
- Naming conflict with built-in function
- How do I split a list into equally-sized chunks?
- How can I make a dictionary from separate lists of keys and values?
- What is the time complexity of popping elements from list in Python?
- Disable assertions in Python
- How can I generate a list of consecutive numbers?
- Accessing a value in a tuple that is in a list
- Python passing list as argument
- is there a pythonic way to try something up to a maximum number of times?
- Confusing […] List in Python: What is it?
- How to delete an item in a list if it exists?
- Flattening a list recursively [duplicate]
- remove None value from a list without removing the 0 value
- Python: Remove Duplicate Items from Nested list
- Changing one dict changes all dicts in a list of dicts [duplicate]
- Python string.join(list) on object array rather than string array
- How to sort multidimensional array by column?
- sum each value in a list of tuples
- Mapping dictionary value to list
- How to change variables fed into a for loop in list form
- Length of longest word in a list
- list extend() to index, inserting list elements not only to the end