if i want a list with all numbers between x and y is there a way to
do this with an inbult function.
i mean i can always construct a function to do this but is there
soemthing like:
nbrs = list(range(50,1 00, 2)) 5 1251
globalrev schrieb:
if i want a list with all numbers between x and y is there a way to
do this with an inbult function.
i mean i can always construct a function to do this but is there
soemthing like:
nbrs = list(range(50,1 00, 2))
range *does* that. use xrange if all you want is to iterate.
Diez
On Tue, May 13, 2008 at 4:05 PM, globalrev <sk*******@yaho o.sewrote:
if i want a list with all numbers between x and y is there a way to
do this with an inbult function.
i mean i can always construct a function to do this but is there
soemthing like:
nbrs = list(range(50,1 00, 2))
What's wrong with just using range()?
>>range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>range(1, 10)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>range(1, 11)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>range(1, 11, 2)
[1, 3, 5, 7, 9]
>>>
--
Jerry
range(50,100,2) returns a list of numbers starting from 50 and less
than 100 with a step size of 2.
list() takes any iterable datatype and converts it into a list.
e.g. list((1, 2, 3)) would return [1,2,3]
& list([1, 2]) would return [1,2]
In this case there is no point of calling range within list since the
output of range is already a list.
Note list(xrange(50, 100,2)) would have made sense if range didnt exist
and you needed a list, but since range does exist, I dont see the
point.
Diez is right when he says to use list to iterate, because creating a
big list just for the sake of iteration would be a terrible waste of
space.
On May 14, 1:16*am, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
globalrev schrieb:
if i want *a list with all numbers between x and y is there a way to
do this with an inbult function.
i mean i can always construct a function to do this but is there
soemthing like:
nbrs = list(range(50,1 00, 2))
range *does* that. use xrange if all you want is to iterate.
Diez
"Diez B. Roggisch" <de***@nospam.w eb.dewrites:
globalrev schrieb:
if i want a list with all numbers between x and y is there a way to
do this with an inbult function.
i mean i can always construct a function to do this but is there
soemthing like:
nbrs = list(range(50,1 00, 2))
range *does* that. use xrange if all you want is to iterate.
Until Python 3.0, where 'range' returns an iterable.
--
\ "It seems intuitively obvious to me, which means that it might |
`\ be wrong." -- Chris Torek |
_o__) |
Ben Finney
2008/5/14 Ethan Furman <ef*****@admail inc.com>:
>
Ben Finney wrote:
Subject: Re: built in list generator?
From: Ben Finney <bi************ ****@benfinney. id.au>
Date: Wed, 14 May 2008 09:43:43 +1000
To: py*********@pyt hon.org
To: py*********@pyt hon.org
Newsgroups: comp.lang.pytho n
"Diez B. Roggisch" <de***@nospam.w eb.dewrites:
globalrev schrieb:
if i want a list with all numbers between x and y is there a way to
do this with an inbult function.
i mean i can always construct a function to do this but is there
soemthing like:
nbrs = list(range(50,1 00, 2))
range *does* that. use xrange if all you want is to iterate.
Until Python 3.0, where 'range' returns an iterable.
Is there a thread somewhere of the discussion for this change? I'm
presuming range is used almost exclusively in loops where a change in the
return type would have no negative effect.
--
http://mail.python.org/pipermail/pyt...il/034534.html
Ethan
-- http://mail.python.org/mailman/listinfo/python-list
--
Wbr, Andrii Mishkovskyi.
He's got a heart of a little child, and he keeps it in a jar on his desk. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mahesh Padmanabhan |
last post by:
Hi,
When list comprehension was added to the language, I had a lot of
trouble understanding it but now that I am familiar with it, I am not
sure how I programmed in Python without it.
Now I see that generator expressions have been added to the language
with 2.4 and I question the need for it. I know that it allows for lazy
evaluation which speeds things up for larger lists but why was it
necessary to add it instead of improving list...
|
by: Mike Meyer |
last post by:
Ok, we've added list comprehensions to the language, and seen that
they were good. We've added generator expressions to the language, and
seen that they were good as well.
I'm left a bit confused, though - when would I use a list comp instead
of a generator expression if I'm going to require 2.4 anyway?
Thanks,
<mike
--
|
by: Steven Bethard |
last post by:
George Sakkis wrote:
> "Steven Bethard" <steven.bethard@gmail.com> wrote:
>> Dict comprehensions were recently rejected:
>> http://www.python.org/peps/pep-0274.html
>> The reason, of course, is that dict comprehensions don't gain you
>> much at all over the dict() constructor plus a generator expression,
>> e.g.:
>> dict((i, chr(65+i)) for i in range(4))
>
> Sure, but the same holds for list comprehensions: list(i*i for i in
|
by: CrispinH |
last post by:
I'm building an application generator and within it a user can create a new
property (for the class they are building). I'd like then to offer a list of
Types - built-in and custom - for this new property to be shown in a combo
box ie similar to Intellisense.
How do you enumerate the Types available? Are their mechanisms for filtering
the list to show only (say) primitive types or custom types or reference
types?
TIA
|
by: wcc |
last post by:
Hello,
Beginner learning Python here. I know filter(lambda x: x > 3, ) will give me a list . What if I only need to
find the first item in the list that returns Ture when applying the
filter function. In this case, I only want to get the 5, and its index
2. Is there a built-in function, or function from a module for that?
I think it is not hard to write a function for this. But knowing
Python is "battery included", I thought I'd...
| |
by: Fabian Steiner |
last post by:
Hello!
I have got a Python "Device" Object which has got a attribute (list)
called children which my contain several other "Device" objects. I
implemented it this way in order to achieve a kind of parent/child
relationship.
Now I would like to get all children of a given "Device" object and
thought that it would be the best way to use recursive function.
|
by: Dave Dean |
last post by:
Hi all,
I'm looking for a way to iterate through a list, two (or more) items at a
time. Basically...
myList =
I'd like to be able to pull out two items at a time - simple examples would
be:
Create this output:
1 2
|
by: danmcleran |
last post by:
All,
I can't seem to find an answer to this question anywhere, but I'm
still looking. My problem is I have a list of values like this:
l =
A value with bit 0x80 set delineates the start of a new packet of
information. What I want to do is to group the packets so that 1, 2, 3
go with the 1st packet tagged 0xF0, 4 ,5, 6 go with the 2nd packet
|
by: Samir |
last post by:
Hi Everyone,
I am relatively new to Python so please forgive me for what seems like
a basic question.
Assume that I have a list, a, composed of nested lists with string
representations of integers, such that
a = , , , ]
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |