Print the first three characters of each item in the list which has more than 5 characters

Ksenija Santare :
items = ["Apple", "Banana", "Cherry", "Date", "Eggfruit", "Fig"]
for word in items:
   print(word[:3])
#prints the first three characters of each item

def string_k(k, str):
  string = []
  text = str.split(" ")
  for x in text:
    if len(x) > k:
      string.append(x)
  return string
k = 6
str = "Apple, Banana, Cherry, Date, Eggfruit, Fig"
print(string_k(k, str))
#This prints out every item in the list that has more than five characters

This is similar to my first question - i have the two separate codes but i don't understand how to get them together to get the output that i need

uday reddy :
items = ["Apple", "Banana", "Cherry", "Date", "Eggfruit", "Fig"]
for item in items:
  if len(item) >= 5:
    print(item[:3])

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=346581&siteId=1