Python Forum
Find number in a text for if statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find number in a text for if statement
#4
(Jul-12-2018, 03:58 PM)nilamo Wrote: As stated by buran, that doesn't look like a string. So I'll help as if it's not a string :)

Try this:
if "bids" in text:
    if any(99 == bid["price"] for bid in text["bids"] if "price" in bid):
        print("go")
    else:
        print("not 99")
else:
    print("invalid text")

Actually I think it is indeed Json data at the source. I didn't really know much about that :(

But your code works actually pretty neat, so thank you!
Reply


Messages In This Thread
RE: Find number in a text for if statement - by BitbyBit - Jul-13-2018, 04:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Brick Number stored as text with openpyxl CAD79 2 687 Apr-17-2024, 10:17 AM
Last Post: CAD79
  find the sum of a series of values that equal a number ancorte 1 574 Oct-30-2023, 05:41 AM
Last Post: Gribouillis
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,559 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Pypdf2 will not find text standenman 2 1,018 Feb-03-2023, 10:52 PM
Last Post: standenman
  read a text file, find all integers, append to list oldtrafford 12 3,937 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  find some word in text list file and a bit change to them RolanRoll 3 1,616 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
  Find and delete above a certain line in text file cubangt 12 3,784 Mar-18-2022, 07:49 PM
Last Post: snippsat
  How to find tags using specific text (timestamps) in a url? q988988 1 1,442 Mar-08-2022, 08:09 AM
Last Post: buran
  Find if chain of characters or number Frankduc 4 1,881 Feb-11-2022, 01:55 PM
Last Post: Frankduc
  Search text in PDF and output its page number. atomxkai 21 9,513 Jan-21-2022, 06:20 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