473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

passing list to a function

Hi,
I have a list [0.2, [1, 1.3], [1, 0.5, 2.1] ...] and need to pass this list as argument in a function and should be able to access elements in the called function, kindly help with code or hints to do this.
Thanks in advance
Feb 1 '12 #1
1 1680
bvdet
2,851 Expert Mod 2GB
Here's one way that encapsulates the list in an object:
Expand|Select|Wrap|Line Numbers
  1. >>> class A:
  2. ...     def __init__(self, *data):
  3. ...         self.data = data
  4. ...     def __getitem__(self, i):
  5. ...         return self.data[i]
  6. ...     
  7. >>> x = A(*[0.2, [1, 1.3], [1, 0.5, 2.1],])
  8. >>> x[1]
  9. [1, 1.3]
  10. >>> y = A(1,2,3,4,5)
  11. >>> y[0]
  12. 1
  13. >>> 
Feb 1 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: keepyourstupidspam | last post by:
Hi, I want to pass a function pointer that is a class member. This is the fn I want to pass the function pointer into: int Scheduler::Add(const unsigned long timeout, void* pFunction, void*...
1
by: vfunc | last post by:
I want to pass a list "node" to a function, read only access of the list is fine, this is the relevant code I have so far typedef std::vector<double> myvec; typedef std::list<myvec> mylist; //...
2
by: jamie | last post by:
hi, I'm trying to pass a List<double> array from C# to a C++ class library but I get the following error: "No overload for method 'zzz' takes '1' arguments" My C++ method in the library has 1...
17
by: Kevin Blount | last post by:
I have a system that I want to try, which requires me, from an aspx page, to call a generic function to work perform one task, then i want to call another function with the results of that task. ...
1
by: burrows.stephen | last post by:
HI all I have a Method that I wish to pass a generic List as a parameter, public void Test (List<Client> temp) { this.ClaimBindingSource.DataSource = temp; }
1
by: User1014 | last post by:
Since you can pass a function to a ... erm...... function.... how to you use the result of a function as the argument for another function instead of passing the actual function to it. i.e. ...
18
by: tbringley | last post by:
I am a c++ newbie, so please excuse the ignorance of this question. I am interested in a way of having a class call a general member function of another class. Specifically, I am trying to...
3
by: ifitzgerald | last post by:
I am attempting to use a wrapper class to the Win32 timer API in a Visual C++ 6.0 MFC application. The callback function needs to have access to the front panel, and as such needs to be a member of...
30
by: Adam | last post by:
Hi, I have a simple printf-like function: int print(const char *format, ...) { char buffer; va_list argptr; int i;
0
by: slenish | last post by:
Hello all, I am wondering if there is a way to expand on the not in list function? I have 5 combo boxes that pull information from a table on the back end. But I want to make it so if the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.