Python Forum
checking if there are numbers in the string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
checking if there are numbers in the string
#8
(Apr-05-2017, 08:17 PM)Sp00f Wrote: can you elaborate on,  "any(c.isdigit() for c in flyTo):"
thanks a lot

In slo-mo:
  • for c in flyTo in an iterator... it iterates each element of flyTo. Since flyTo is a string the elements are characters
  • c.isdigit() is True if c is a digit
  • for c in flyTo builds a list of True or False, once for each character
  • any(some list) is True if there is at least one element that evaluates to True in the list
So any(c.isdigit() for c in flyTo) evaluates to True is at least one character of flyTo is a digit.

A different way of doing it:

len(flyTo)!=len(flyTo.translate(None,'0123456789'))
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Messages In This Thread
RE: checking if there are numbers in the string - by Ofnuts - Apr-05-2017, 10:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pulling Specifics Words/Numbers from String bigpapa 2 823 May-01-2023, 07:22 PM
Last Post: bigpapa
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,613 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  Checking if a string contains all or any elements of a list k1llcod3 1 1,183 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  Find and Replace numbers in String giddyhead 2 1,291 Jul-17-2022, 06:22 PM
Last Post: giddyhead
  Finding line numbers starting with certain string Sutsro 3 2,607 Jun-27-2020, 12:36 PM
Last Post: Yoriz
  checking a string for two instances of .. Skaperen 2 1,626 May-13-2020, 09:58 PM
Last Post: Skaperen
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,808 May-09-2019, 12:19 PM
Last Post: Pleiades
  String format checking? MuntyScruntfundle 1 2,468 Mar-06-2019, 12:01 PM
Last Post: buran
  Extract numbers from string ian 1 2,845 Apr-28-2018, 10:40 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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