4. Write a Python program to get the smallest number from a list.
5. Write a Python program to count the number of strings where the string length is 2 or more and the first and last character are the same from a given list of strings.
6. Write a Python program to remove duplicates from a list.
7. Write a Python program to check if a list is empty or not.
8. Write a Python program to clone or copy a list.
9. Write a Python program to find the list of words that are longer than n from a given list of words.
10. Write a Python program that takes two lists and returns True if they have at least one common member.
Ответы на вопрос
4. Smallest number in a list
numbers = [12, 5, 8, 1, 9]
print(min(numbers))
5. Count strings with the same first and last character
words = ['aba', 'abc', 'aa', 'b', 'hello']
count = sum(1 for word in words if len(word) >= 2 and word[0] == word[-1])
print(count)
6. Remove duplicates from a list
numbers = [1, 2, 2, 3, 1, 4]
unique_numbers = []
for number in numbers:
if number not in unique_numbers:
unique_numbers.append(number)
print(unique_numbers)
7. Check whether a list is empty
items = []
if not items:
print('The list is empty')
else:
print('The list is not empty')
8. Copy a list
original = [1, 2, 3]
copy_list = original[:]
print(copy_list)
9. Words longer than n
words = ['cat', 'elephant', 'book', 'computer']
n = 4
result = [word for word in words if len(word) > n]
print(result)
10. Check for a common member in two lists
list1 = [1, 2, 3]
list2 = [3, 4, 5]
print(bool(set(list1) & set(list2)))
Похожие вопросы
Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili

