0

Print the elements whose array length is greater than or equal to 4, such as

things = ['jump','hop','skip','tip',leap']
Nick
  • 138,499
  • 22
  • 57
  • 95

2 Answers2

0

I would advice you to come up with the answer for this yourself. Some hints are :

  1. Use a 'for' loop to iterate through each element of the list LINK Example:
fruits = ["apple", "banana", "cherry"]

for x in fruits:
 print(x)
  1. Within the loop, use len() to check the length of each element of the list. Example:
 if len(element1) >=4: 
    do something

Full code as below

fruits = ["apple", "banana", "cherry"]

for x in fruits:
 if len(x) >=4: 
   print(x)

Sivaram Rasathurai
  • 5,533
  • 3
  • 22
  • 45
Anupam Chand
  • 2,209
  • 1
  • 5
  • 14
0

You can check the element lenght is greater than four then you can add them into the desired list

new_elements =[element for element in things if len(element)>=4]
print(new_elements)

enter image description here

Sivaram Rasathurai
  • 5,533
  • 3
  • 22
  • 45