Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Word Generator
#3
Quote:
def generate_word(length = 5):
return "".join(random.choice([VOWELS, CONSONANTS][_ % 2]) for _ in range(length))

Please, only use underscore for a variable name if you're not going to use that variable at all. [_ % 2] looks like some Perl nonsense, and shouldn't be anywhere in your code.
Reply


Messages In This Thread
Word Generator - by WordGenerator - Sep-17-2017, 04:02 PM
RE: Word Generator - by ichabod801 - Sep-17-2017, 06:49 PM
RE: Word Generator - by nilamo - Sep-21-2017, 06:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,488 Aug-12-2021, 04:25 PM
Last Post: palladium
  Python Speech recognition, word by word AceScottie 6 15,985 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  print a word after specific word search evilcode1 8 4,820 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  difference between word: and word[:] in for loop zowhair 2 3,666 Mar-03-2018, 07:24 AM
Last Post: zowhair
  receive from a generator, send to a generator Skaperen 9 5,497 Feb-05-2018, 06:26 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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