Python Forum
Unable to understand a statement in an existing code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to understand a statement in an existing code
#2
This is a list comprehension. It is a compact way of writing this:
temp = []
for word in tokens:
    if word.isalpha()
        temp.append(word)
tokens = temp
tokens = [] says the resulting list is assigned to "tokens".
[word for word in tokens] says the list is going to be made up of words from the original "tokens".
if isalpha(word) says only include words that are "isalpha".
Reply


Messages In This Thread
RE: Unable to understand a statement in an existing code - by deanhystad - Aug-01-2020, 09:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python best library for Excel reports & review of existing code MasterOfDestr 4 819 Feb-14-2024, 03:39 PM
Last Post: MasterOfDestr
  Unable to understand the meaning of the line of code. jahuja73 0 345 Jan-23-2024, 05:09 AM
Last Post: jahuja73
Photo Python code: While loop with if statement HAMOUDA 1 632 Sep-18-2023, 11:18 AM
Last Post: deanhystad
  An unexplainable error in .format statement - but only in a larger piece of code? ToniE 4 750 Sep-05-2023, 12:50 PM
Last Post: ToniE
  code won't advance to next statement MCL169 2 790 Apr-11-2023, 09:44 PM
Last Post: Larz60+
  add mqtt feature to existing code Positron79 0 612 Jan-31-2023, 05:56 PM
Last Post: Positron79
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,730 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
Photo Visual studio code unable to color syntax on python interpreter tomtom 4 7,056 Mar-02-2022, 01:23 AM
Last Post: tomtom
  Unable to understand how given code takes a fixed input value, without inputting. jahuja73 4 2,782 Jan-28-2021, 05:22 PM
Last Post: snippsat
  Don't understand example code from a textbook lil_fentanyl 1 1,864 Jan-25-2021, 07:02 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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