```
def second_largest(nums):
the, sec = 0, 0
if nums[0] > nums[1]:
the, sec = nums[0], nums[1]
else:
the, sec = nums[1], nums[0]
for num in nums:
if num > sec:
if num >= the:
the, sec = num, the
else:
sec = num
return sec
```

This is my code to get second largest element from the list. I assumed that a list has at least two elements. However, it gives me 'gamma' not 'delta' from the input below.

```
print(second_largest(['alpha', 'gamma','beta','delta']))
```

`sorted(['alpha', 'gamma','beta','delta'], reverse=True)[1]`

? – zwer 49 mins ago`heapq.nlargest`

– roippi 34 mins ago