Python Forum
If a set element has digits in the element
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If a set element has digits in the element
#1
Good evening!
I'm trying to find if an element of a set has a digit/digits as a part of an element.
I'm using ".isdigit" but it does not work...
I have to test the set if it has just one element or it is multiple element's set.
vid_set = set(("apple", "banana",  "banana","cherry","cher123ry")) 
if len(vid_set) > 1 :
    for e_vid in vid_set :                    
        print(' SET Element ',e_vid)
        if e_vid.isdigit():
            print(f" MIxED ELEMENTs SET - > {e_vid}")
Thank you.
Tester_V
Reply
#2
I don't know what is wrong with me...
Sorry for taking your time!
I fixed it.
import re
if len(vid_set) > 1 :
    for e_vid in vid_set : 
        if re.findall(r'\d+',e_vid) :
            print(e_vid)
Thank you!
Tester_V
Reply
#3
(Mar-25-2024, 05:10 AM)tester_V Wrote: I fixed it.
Better use if re.search(r'\d', e_vid) than if re.findall(r'\d+', e_vid). It does a little less useless work.
« We can solve any problem by introducing an extra level of indirection »
Reply
#4
import re
vid_set = set(("apple", "apple2e", "banana",  "banana2", "cherry", "cherry2"))
print({x for x in vid_set if re.search(r"\d", x)})
Output:
{'banana2', 'apple2e', 'cherry2'}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Fixture not returning webdriver element Nik1811 1 225 Apr-15-2024, 04:39 PM
Last Post: Nik1811
  element in list detection problem jacksfrustration 5 408 Apr-11-2024, 05:44 PM
Last Post: deanhystad
  Elegant way to apply each element of an array to a dataframe? sawtooth500 7 436 Mar-29-2024, 05:51 PM
Last Post: deanhystad
  Variable for the value element in the index function?? Learner1 8 672 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Searche each element of each tuple based 3 numbes zinho 8 890 Dec-11-2023, 05:14 PM
Last Post: zinho
  list in dicitonary element problem jacksfrustration 3 721 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  search an element in pandas series learningPython 5 1,428 Apr-30-2023, 08:34 AM
Last Post: learningPython
Question Inserting Numerical Value to the Element in Optionlist and Printing it into Entry drbilgehanbakirhan 1 824 Jan-30-2023, 05:16 AM
Last Post: deanhystad
  How to separate the values in an element to add them monty024 4 1,036 Jan-23-2023, 04:28 AM
Last Post: deanhystad
  compare and find the nearest element ? mr_gentle_sausage 4 1,055 Jan-15-2023, 07:11 AM
Last Post: DPaul

Forum Jump:

User Panel Messages

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