how to check from a python string list which is the largest item and copy it to another list. i was trying this. but i dosnt Works.
cad_1 = ['hello', 'hello', 'ewe', 'uwu']
cad_final = {i,j for i,j in Cad_1 if len(i)>=len(j)}
print(cad_final);
You can first create a dictionary with the respective string length:
my_length_list = {i:len(i) for i in my_list}
and then get the largest element by
import operator
max_string_len = max(my_length_list.items(), key=operator.itemgetter(1))[0]
and write this value in another list
max_string_list = [max_string_len]
max(my_list, key=len).
NameErrorbefore even getting to the second line... the second line is a set comprehension and you can't loop through a list like that anyway. If you want help you need to clarify exactly what the error is.hello,ewe, anduwuvariables or string? Can you clarify what do you mean by largest? Largest value? Longest string? By alphabetical order?