Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reverse printed words
#1
If words include letter "E" then I need to return these words and another words I need to print out. And I need to reverse returned words.

lib = ["politsei", "mehine","panda","ment","kusi", "treener","leidma", "jooks", "muksid","president"]

def sisend(lib, b):

result =[]

for i in lib:
if b in i:
result.append(i)
return result

print(sisend(lib, 'e'))
Reply
#2
There is a python command for iterating through a list in reverse order.
Reply
#3
I know that ....reverse() command. Right now code print letters with specific word, but code needs to print words without this letter and reverse returned(with specific letter) words.
Reply
#4
Reverse the order of the words or reverse the letters in the word? Either way it is something I would use for this problem. Maybe twice. Could you provide sample output to help me better understand what your program is supposed to do?
Reply
#5
Reversing the words is as simple as...

"word"[::-1]
Performing that on each item in a list is made easy with the map() built-in function too.
Reply
#6
lib = ["politsei", "mehine","panda","ment","kusi", "treener","leidma", "jooks", "muksid","president"]

def sisend(lib, b):
 result=[]

 for i in lib:
  if b in i:
   result.append(i[::-1])
  else:
    result.append(i)
 return result

print(sisend(lib, 'e'))
Reply
#7
(Apr-20-2020, 09:29 PM)deanhystad Wrote: Reverse the order of the words or reverse the letters in the word? Either way it is something I would use for this problem. Maybe twice. Could you provide sample output to help me better understand what your program is supposed to do?

output:"panda","kusi" "jooks", "muksid"(all words without E)and then returned words(with letter "E") in reversed output output: president, leidma, treener, ment, mehine, politsei
Reply
#8
I would process the list in reverse order and build a new list. If the word contains the letter, append to the new list. If the word does not contain the letter insert in the front of the list.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  coma separator is printed on a new line for some reason tester_V 4 498 Feb-02-2024, 06:06 PM
Last Post: tester_V
  How can histogram bins be separated and reduce number of labels printed on x-axis? cadena 1 895 Sep-07-2022, 09:47 AM
Last Post: Larz60+
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,826 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  I get "None" at the end of my printed result. dyshkant 3 2,666 Sep-06-2019, 06:31 PM
Last Post: dyshkant
  bytes not being printed as expected Skaperen 2 2,381 Aug-27-2019, 05:33 AM
Last Post: Skaperen
  Change linenumber and filename printed in exceptions like #line in C kryptomatrix 2 2,683 Jul-12-2019, 06:01 AM
Last Post: Gribouillis
  Putting an array for each string that is printed to a loop ClaudioSimonetti 1 2,354 Feb-05-2019, 12:52 PM
Last Post: perfringo
  Compare all words in input() to all words in file Trianne 1 2,776 Oct-05-2018, 06:27 PM
Last Post: ichabod801
  Why A will be printed twice in the picture Shen 3 4,099 Jul-25-2018, 01:16 PM
Last Post: stranac
  0 error but Not printed Piqurs 5 3,983 Jul-14-2018, 04:43 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020