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);
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]