The length of the list items
Write a program to receive a list of strings and then pour and print the length of each item from the list in another list
Write a program to receive a list of strings and then pour and print the length of each item from the list in another list
input_strings = input("لطفاً رشتهها را با کاما جدا کنید: ").split(',') # Remove the empty space from the beginning and end of each string input_strings = [s.strip() for s in input_strings] # Calculate the length of each string and save in the new list lengths = [len(s) for s in input_strings] # View results print("طول هر رشته:") print(lengths)
def get_lengths(strings, separator): string_list = strings.split(separator) lengths = [len(s.strip()) for s in string_list] return lengths input_strings = input("لطفاً لیستی از رشتهها را وارد کنید: ") separator = input("لطفاً جداکننده مورد نظر را وارد کنید: ") result = get_lengths(input_strings, separator) print("طول هر رشته در لیست:", result)
def lengths_of_strings(strings): lengths = [len(s) for s in strings] return lengths strings = ["pencil","book","couch"] result = lengths_of_strings(strings) print("طول هر رشته در لیست:", result)
def get_lengths(strings): lengths = [] for string in strings: lengths.append(len(string)) return lengths strings = input("string: ").split(' ') lengths = get_lengths(strings) print("length: ", lengths)
list = [] while 1: strings = input("please enter a string: ") if strings == "exit": break else: list.append(strings) list_2 = [] for i in list: list_2.append(len(i)) print(list_2)
read_line = list(map(str , input().split())) s = [] for i in read_line : counter = 0 for item in i : counter += 1 s.append(counter) print(s)
list_ = [] li = input("Enter a space between strings: ").split(" ") for i in li: list_.append(len(i)) print(list_)
Submitting answers is currently unavailable.
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.