How would i write a function that prints all numbers in the range a to b(inclusive) that have all digits belonging to the set (1,3,4,8,9). The function takes two integer arguments:A and B...
I understood the question and i have seen an example with the (dictionary.txt), but it was to check vowels in words. So for this one i don't know how i would check for those numbers in the range which the user wishes....Lets say from 10000 to 1,000,000
1 1408 bvdet 2,851
Expert Mod 2GB
The first hurdle is to convert the number to a list of the individual digits and create a set object from the list. Then you can do set1.issubset(s0) to determine if all the digits are in the set (1,3,4,8,9). There are a couple of ways to do this off the top of my head. This is probably the easiest: - >>> n = 1234567890
-
>>> list(str(n))
-
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
-
>>> map(int, list(str(n)))
-
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
-
>>> [int(i) for i in list(str(n))]
-
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
-
>>> set([int(i) for i in list(str(n))])
The other way is a loop using divmod(): - def numtodigits(n):
-
output = []
-
while True:
-
a,b = divmod(n, 10)
-
output.insert(0, b)
-
n = a
-
if not a: return output
-
'''
-
>>> numtodigits(1230)
-
[1, 2, 3, 0]
-
>>>
-
'''
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ken |
last post by:
I am getting this error from a gcc compile and I was wondering whether
this was 100% valid. This seems a little extreme to me the c++ cast
operators appear to only work on objects which defeats...
|
by: jimjim |
last post by:
Hello,
My question concerns as to how a pointer is passed by reference as a
function argument. The following is from code taken from the MICO
implementation of the CORBA specification.
in...
|
by: Baldy |
last post by:
really tricky one here.
I want to be able to call a function but the function name is in a variable.
The code is a security module that is querying a table that stores names of
functions, forms,...
|
by: Hai Nguyen |
last post by:
Hi everyone
I'm writting a javascript for my validators. Some of them will be validated
or server side, some of them will be validated on client side. Since I don't
want to mix my javascript...
|
by: Geagleeye |
last post by:
Hi,
Im a rookie in vba, and therefor got a problem.
i do have folwing records
F G
---------------
2 3
2 5
6 7
|
by: noridotjabi |
last post by:
Is there any way in C to write source which would make an executable
that excepted modifications. For instance say we have modable program
that excepts plugins. That starts with a menu.
1)Add...
|
by: howachen |
last post by:
I have a function foo(), I want all my page can call this method
without include / require
I know I can set in php.ini by setting the auto_prepend...
but this will cause overhead as every file...
|
by: Java1963 |
last post by:
Need help with writting an application that prompt for and read a double value representing a monetary amount.
--------------------------------------------------------------------------------
...
|
by: rahulbsbs |
last post by:
Sir how can i get the ip address of the remote system by writting a java code,ie i want to get ip address of the remote system that is connected to my server computer ,the ip address must be...
|
by: Alan Coats |
last post by:
I have the following function in php which works out a cut of date which is the Tuesday the week prior to the actual date. As I am new to C#, any suggestions on how to do similar in C#?
function...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |