Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
boolean result of loop
#15
you can do

if 'foo' in d:
    something = d['foo']
else:
    something = False
or you can do

something = d.get('foo',False)
see... 1 statement instead of 4

bonus points: who can show how to do this in 1 statement for a sequence

if x < len(s):
    something = s[x]
else:
    something = False
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
boolean result of loop - by Skaperen - Mar-31-2017, 01:47 AM
RE: boolean result of loop - by wavic - Mar-31-2017, 02:27 AM
RE: boolean result of loop - by Skaperen - Mar-31-2017, 05:50 AM
RE: boolean result of loop - by Ofnuts - Mar-31-2017, 08:30 AM
RE: boolean result of loop - by Skaperen - Apr-01-2017, 04:10 AM
RE: boolean result of loop - by buran - Apr-01-2017, 04:48 AM
RE: boolean result of loop - by wavic - Apr-01-2017, 05:02 AM
RE: boolean result of loop - by buran - Apr-01-2017, 05:13 AM
RE: boolean result of loop - by wavic - Apr-01-2017, 06:09 AM
RE: boolean result of loop - by ichabod801 - Apr-01-2017, 10:45 AM
RE: boolean result of loop - by wavic - Apr-01-2017, 11:20 AM
RE: boolean result of loop - by buran - Apr-01-2017, 12:07 PM
RE: boolean result of loop - by ichabod801 - Apr-01-2017, 12:42 PM
RE: boolean result of loop - by Skaperen - Apr-02-2017, 01:03 AM
RE: boolean result of loop - by Skaperen - Apr-02-2017, 02:52 AM
RE: boolean result of loop - by Ofnuts - Apr-02-2017, 08:33 PM
RE: boolean result of loop - by wavic - Apr-02-2017, 11:34 PM
RE: boolean result of loop - by micseydel - Apr-02-2017, 11:50 PM
RE: boolean result of loop - by wavic - Apr-02-2017, 11:56 PM
RE: boolean result of loop - by ichabod801 - Apr-03-2017, 12:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Running A Loop Until You See A Particular Result knight2000 6 32,112 Sep-04-2021, 08:55 AM
Last Post: knight2000
  Noob Alert! Wrong result using loop and if statemnent GJG 7 3,075 Dec-19-2020, 05:18 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