I am a new Python programmer and trying some stuff out. I want to create a list of strings and loop through my list to check the size of each element, if the size is greater than 5, then I will change that string into an uppercase string. I am stuck on how to access that element. Below is some of the code that I have written. Thank you in advance!
lis = ['heeeeellllooo','world','low','higggghhh']
for elem in list:
if len(lis[elem]) > 5:
list[elem].upper()
use a
list comprehensionwithternary operator:You can also use
enumerate(),enumeratereturns atuplewhole first item is the index of the element and the second item is the element itself.This method modifies the original list.
How are lists implemented?: