Python Forum
For loops, strings and printing words with even characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For loops, strings and printing words with even characters
#5
(Sep-13-2018, 03:07 PM)Drone4four Wrote:
mystring = "Secret agents are super good at staying hidden."
mystring = mystring.split()
counted_string = len(mystring)
# int(counted_string)
for word in mystring:    
    if counted_string %2 == 0:
        print(word)
counted_string is the length of the list (8), you need it to be the length of EACH string (word) as you go through the loop.
I am trying to help you, really, even if it doesn't always seem that way
Reply


Messages In This Thread
RE: For loops, strings and printing words with even characters - by gruntfutuk - Sep-13-2018, 03:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand strings and lists of strings Konstantin23 2 778 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 1,782 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,827 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  printing strings with format leodavinci1990 1 1,599 Aug-21-2020, 02:00 AM
Last Post: micseydel
  Introduction to escaping characters in strings Geelong_crazy 1 2,871 Jul-18-2020, 06:58 PM
Last Post: DT2000
  How to find the first and last of one of several characters in a list of strings? tadsss 2 2,209 Jun-02-2020, 05:23 PM
Last Post: bowlofred
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,794 May-15-2020, 01:37 PM
Last Post: snippsat
  Trying to get unique words from a set of strings garam0 5 5,179 Apr-15-2020, 06:24 PM
Last Post: garam0
  Split a long string into other strings with no delimiters/characters krewlaz 4 2,803 Nov-15-2019, 02:48 PM
Last Post: ichabod801
  Finding multiple strings between the two same strings Slither 1 2,531 Jun-05-2019, 09:02 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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