Hiya!
I would like to take a partial slice of a fairly complex array. The
source looks something like
array
(
[Full Name] ==array
(
[p_id] ==NN
[field1] ==blah
[fieldN] ==blah
[numbers] ==array
{
[800-555-1212] =="cell"
[123-456-7890] =="home"
]
[emails] ==array
(
[em***@add.re.ss] ==>
[e.****@addr.ess] ==>
)
)
)
for many fields 1-N across many people. I want to end up with an
array like
array
(
[Full Name] ==array
(
[display] =="Full Name"
[link] =="http://example.com/p_id=NN"
)
)
combining some pieces from the source array and adding other pieces
either constructed (eg link) or static (maybe).
Is there an easy way to do this across my entire source array without
just looping over it myself?
Why would I do this, you ask? Well, I have to print a list a bunch of
times and I am tired of rewriting the code :-) I'll need to be able
to specify display value, link target, and/or form field name for
starters; a separate array will control how to present the data so
that I can end up with anything from a space-separated list to a row
in a table to a bunch of checkboxes or radio buttons and so on. I'm
certainly open to simpler ways to accomplish the same thing, but a
function that takes data and control arrays and handles the
presentation certainly seems nice at the moment :-)
TIA & HAND
P.S. -- This is my first post-by-google, so I'm interested in seeing
how the formatting comes out. Wish me luck :-)
:-D
--
David T-G
see http://justpickone.org/email/ 2 1599
On 18.09.2007 06:29 David TG wrote:
Hiya!
I would like to take a partial slice of a fairly complex array. The
source looks something like
array
(
[Full Name] ==array
(
[p_id] ==NN
[field1] ==blah
[fieldN] ==blah
[numbers] ==array
{
[800-555-1212] =="cell"
[123-456-7890] =="home"
]
[emails] ==array
(
[em***@add.re.ss] ==>
[e.****@addr.ess] ==>
)
)
)
for many fields 1-N across many people. I want to end up with an
array like
array
(
[Full Name] ==array
(
[display] =="Full Name"
[link] =="http://example.com/p_id=NN"
)
)
combining some pieces from the source array and adding other pieces
either constructed (eg link) or static (maybe).
Is there an easy way to do this across my entire source array without
just looping over it myself?
There's apparently no built-in function that can handle this. If, for
some reason, you're unhappy with "foreach", you can try array_map() or
array_walk(). The modern OO approach would be to use an iterator,
perhaps even different ones for different purposes.
class DisplayIterator implements Iterator
{
function __construct($ar y) {
$this->ary = $ary;
....
function next() {
// get next element and format it how you want
}
....
foreach(new DisplayIterator ($yourArray) as $element)
// do whatever with $element
>
Why would I do this, you ask? Well, I have to print a list a bunch of
times and I am tired of rewriting the code :-) I'll need to be able
to specify display value, link target, and/or form field name for
starters; a separate array will control how to present the data so
that I can end up with anything from a space-separated list to a row
in a table to a bunch of checkboxes or radio buttons and so on. I'm
certainly open to simpler ways to accomplish the same thing, but a
function that takes data and control arrays and handles the
presentation certainly seems nice at the moment :-)
TIA & HAND
P.S. -- This is my first post-by-google, so I'm interested in seeing
how the formatting comes out. Wish me luck :-)
:-D
--
David T-G
see http://justpickone.org/email/
The formatting is ok, but you should add a space after "--".
--
gosha bine
makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
gosha, et al --
gosha bine wrote:
On 18.09.2007 06:29 David TG wrote:
I would like to take a partial slice of a fairly complex array. The
source looks something like
....
Is there an easy way to do this across my entire source array without
just looping over it myself?
There's apparently no built-in function that can handle this. If, for
some reason, you're unhappy with "foreach", you can try array_map() or
Ahhhh... Those both sound familiar; I'll check 'em out.
array_walk(). The modern OO approach would be to use an iterator,
perhaps even different ones for different purposes.
[snip]
Oho! Thanks; I'll have to play with that.
>
....
P.S. -- This is my first post-by-google, so I'm interested in seeing
how the formatting comes out. Wish me luck :-)
....
>
The formatting is ok, but you should add a space after "--".
Heh. That's a web form for you. It was there originally :-/
I also noticed lots of extra linefeeds in my post. I'm not sure
whether I like 'em or not, as wrapping lines is a good thing but not
doing it where I want gets on my nerves.
Thanks again & HAND
:-D
--
David T-G This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Yun Mao |
last post by:
Hi python gurus,
I have some questions when I'm using python numeric:
1. When I do v = u, it seems u and v still point to the same
memory. e.g. When I do v=0, u will be zero out as well.
What's the right way to duplicate an array? Now I have to do v =
dot(u, identity(N)), which is kind of silly.
2. Is there a way to do Matlab style slicing? e.g. if I have
i = array()
|
by: seberino |
last post by:
Many people I know ask why Python does slicing the way it does.....
Can anyone /please/ give me a good defense/justification???
I'm referring to why mystring gives me
elements 0, 1, 2 and 3 but *NOT* mystring (5th element).
Many people don't like idea that 5th element is not invited.
(BTW, yes I'm aware of the explanation where slicing
|
by: Bryan Olson |
last post by:
I recently wrote a module supporting value-shared slicing. I
don't know if this functionality already existed somewhere, but
I think it's useful enough that other Pythoners might want it,
so here it is.
Also, my recent notes on Python warts with respect to negative
indexes were based on problems I encoutered debugging this
module, so I'm posting it partially as a concrete example of
what I was talking about.
|
by: jbperez808 |
last post by:
>>> rs='AUGCUAGACGUGGAGUAG'
>>> rs='GAG'
Traceback (most recent call last):
File "<pyshell#119>", line 1, in ?
rs='GAG'
TypeError: object doesn't support slice assignment
You can't assign to a section of a sliced string in
Python 2.3 and there doesn't seem to be mention of this
as a Python 2.4 feature (don't have time to actually try
|
by: jeg |
last post by:
dear all,
i'm an astronomer working with 2d images -- 2d numarrays. i have a
script which basically does some operations on some images, and one of
the first steps is to find a galaxy on an image (at, say, a known x,y
coord), and create a sub-image by slicing out part of the larger array
to create a more managable smaller one (e.g. 50x50 pixels from a
1000x1000 array).
i was running this fine under python 2.3.4, but due to the...
| |
by: baibaichen |
last post by:
i have written some code to verify how to disable slicing copy
according C++ Gotchas item 30
the follow is my class hierarchy, and note that B is abstract class!!
class B
{
public:
explicit B(INT32 i =0):i_(i){}
virtual ~B(){}
|
by: jccorreu |
last post by:
I'm taking in data from multiple files that represents complex numbers
for charateristics of different elements. I begin with arrays of
doubles and interpolate to get standard values in real and imaginary
portions. To this end I have some dynamic arrays of doubles to hold
the standardized individual rael and imaginary parts.
double *ANreal, *ANimag, *BNreal, *BNimag, *CNreal, *CNimag;
ANreal = new double;
ANimag = new double;
|
by: perroe |
last post by:
Hi
I have a array of complex numbers that are stored in a simple double
array. This is done since the array is part of an wrapper for an
external C library, and the imaginary part of the first element, and
the last element are known to be 0. I've implemented a -operator
that returns a ComplexReference object that basically maps a
complex<doubleinto the storage used in the array.
What I would like to do is using the ComplexReference...
|
by: Yves Dorfsman |
last post by:
Is there a way to do:
x =
x
That would return:
I am surprised this notation is not supported, it seems intuitive.
A concrete example of the sort of thing I want to do:
|
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: 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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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: 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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |