There is a task, completed it partially and stuck. I can not figure out how to organize the implementation of the last 3rd paragraph. I would be very grateful if you help me figure it out.
Task: Write the counter (T) function:
- host tuple consisting of Latin alphabet strings, for example, ("ABC", "abc")
- leading lines to a single (upper or lower) case defining the number of unique Latin characters for each line
- (the string "Aaa" contains only 1 unique character) returns the length of the line with the maximum number of unique characters (if there are several such lines, then the largest of them)
Program Code:
def counter(T): # ΡΠΈΡΠ°Π΅ΠΌ ΡΡΡΠΎΠΊΡ ΠΈ ΠΏΡΠΈΠ²ΠΎΠ΄ΠΈΠΌ ΠΊ Π½ΠΈΠΆΠ½Π΅ΠΌΡ ΡΠ΅Π³ΠΈΡΡΡΡ, ΡΠ°Π·Π±ΠΈΠ²Π°Π΅ΠΌ Π½Π° ΡΡΡΠΎΠΊΠΈ T=str(T) T=T[2:-2] T=T.lower().split("\', \'") length_unic=[] length_str=[] length_max = 0 # ΠΈΠ·ΠΌΠ΅Π½ΡΠ΅ΠΌ ΡΠΈΡΠ»ΠΎ ΡΠ½ΠΈΠΊΠ°Π»ΡΠ½ΡΡ
ΡΠΈΠΌΠ²ΠΎΠ»ΠΎΠ² ΠΈ Π΄Π»ΠΈΠ½Ρ ΡΡΡΠΎΠΊ, Π·Π°ΠΏΠΈΡΡΠ²Π°Π΅ΠΌ Π² ΡΠΏΠΈΡΠΎΠΊ for word in T: length_current = len(word) if length_current > length_max: length_max = length_current length_str.append(length_current) unic = set() for letter in word: unic.add(letter) length_unic.append(len(unic)) # ΠΏΠΎΠΈΡΠΊ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡΠ½ΠΎΠ³ΠΎ ΡΠ½ΠΈΠΊΠ°Π»ΡΠ½ΠΎΠ³ΠΎ max=0 for i in range(len(length_unic)): if length_unic[i] > max: max = length_unic[i] # ΠΈΠ·ΠΌΠ΅ΡΠ΅Π½ΠΈΠ΅ Π΄Π»ΠΈΠ½Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ ΡΡΡΠΎΠΊΠΈ max_len_unic = length_unic[0] for i in range(1,len(T)): if length_unic[i] >= max_len_unic: max_len_unic = length_unic[i] max_len_str = length_str[0] if length_str[i] >= max_len_str: max_len_str = length_unic[i] #print(length_max) print(length_unic) print(length_str) T=('Aa', 'ab', 'AaAa', 'AaAaAa', 'ABBA') counter(T)