I have a list that only has one item. I know this list only has one item because it is the output of a MySQL query that will always have just one result.
MySQL Query:
SELECT MAX(date) FROM db.table;
List result:
['20170307']
Now I must access the item in this list. I have two options:
1) By position
max_date = list[0]
print(max_date)
2) By iterating through item(s)
for item in list:
max_date = item
print(max_date)
Can someone please explain which approach is more appropriate in terms performance, readability, and overall best practice? My IDE raises a red flag when I use approach #2 but is it safe to ignore if I'm confident my list will always have one item?