Function « List « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » List » Function 

1. Can you list the keyword arguments a Python function receives?    stackoverflow.com

I have a dict, which I need to pass key/values as keyword arguments.. For example..

d_args = {'kw1': 'value1', 'kw2': 'value2'}
example(**d_args)
This works fine, but if there are values in the d_args dict ...

2. python, functions running from a list and adding to a list through functions    stackoverflow.com

How do I run a function on a loop so all the results go straight into a list and is there a way to run a function which acts on all ...

3. list named with a function argument in python    stackoverflow.com

I get the feeling this is probably something I should know but I can't think of it right now. I'm trying to get a function to build a list where the ...

4. Getting list of parameters inside python function    stackoverflow.com

Is there an easy way to be inside a python function and get a list of the parameter names? For example:

def func(a,b,c):
    print magic_that_does_what_I_want()

>>> func()
['a','b','c']
Thanks

5. Call a function with argument list in python    stackoverflow.com

I'm trying to call a function inside another function in python, but can't find the right syntax. What I want to do is something like this:

def wrapper(func, args):
    ...

6. What is the idiomatic way of invoking a list of functions in Python?    stackoverflow.com

I have a list of callback functions that I need to invoke when an event is fired. Is this idiomatic python?

def first_callback(m):
  print 'first ' + m

def second_callback(m):
  print ...

7. What is the runtime complexity of python list functions?    stackoverflow.com

I was writing a python function that looked something like this

def foo(some_list):
   for i in range(0, len(some_list)):
       bar(some_list[i], i)
so that it was called ...

8. How do I do this in Python? List to function    stackoverflow.com

def getStuff(x):
    return 'stuff'+x

def getData(x):
    return 'data'+x


thefunctions = []
thefunctions.append("getStuff")
thefunctions.append("getData")

for i in thefunctions:
   print i('abc')
Is this possible? Thank you.

9. List comprehension and functions    stackoverflow.com

I'm a little confusing when try something like this

b = [lambda x:x**i for i in range(11)]
When I then try b[1](2) I have 1024 as a result that is wrong. But when ...

10. Python passing list as argument    stackoverflow.com

If i were to run this code:

def function(y):
    y.append('yes')
    return y

example = list()
function(example)
print(example)
Why would it return ['yes'] even though i am not directly changing the ...

11. Is there a Python equivalent of Ruby's 'any?' function?    stackoverflow.com

In Ruby, you can call Enumerable#any? on a enumerable object to see if any of its elements satisfies the predicate you pass in the block. Like so:

lst.any?{|e| pred(e) }
In ...

12. Apply function to one element of a list in Python    stackoverflow.com

I'm looking for a concise and functional style way to apply a function to one element of a tuple and return the new tuple, in Python. For example, for the following input:

inp ...

13. Python list as *args?    stackoverflow.com

I have two Python functions, both of which take variable arguments in their function definitions. To give a simple example:

def func1(*args):
    for arg in args:
    ...

14. Pass elements of a list as arguments to a function in python    stackoverflow.com

I'm building a simple interpreter in python and I'm having trouble handling differing numbers of arguments to my functions. My current method is to get a list of the commands/arguments as ...

15. list exported functions from dll with ctypes    stackoverflow.com

Is there anyway to know which functions exported from the dll througth python foreign function library -ctypes- and if possible to know details about the exported functions throught ctypes. if yes could someone ...

16. Python code refactoring question. Applying functions to multiple elements    stackoverflow.com

I have code that looks something like this:

self.ui.foo.setEnabled(False)
self.ui.bar.setEnabled(False)
self.ui.item.setEnabled(False)
self.ui.item2.setEnabled(False)
self.ui.item3.setEnabled(False)
And I would like to turn it into something like this:
items = [foo,bar,item,item2,item3]
for elm in items:
    self.ui.elm.setEnabled(False)
But obviously just having the ...

17. how to access the list in different function    stackoverflow.com

I have made a class in which there are 3 functions.

  1. def maxvalue
  2. def min value
  3. def getAction
In the def maxvalue function, I have made a list of actions. I want that list ...

18. Python list function argument names    stackoverflow.com

Is there a way to get the argument names a function takes?

def foo(bar, buz):
    pass
magical_way(foo) == ["bar", "buz"]

19. Pass each element of a list to a function that takes multiple arguments in Python?    stackoverflow.com

For example, if I have a=[['a','b','c'],[1,2,3],['d','e','f'],[4,5,6]] How can I get each element of a to be an argument of say, zip without having to type zip(a[0],a[1],a[2],a[3])?

20. Why doesn't Pylint like built-in functions?    stackoverflow.com

I have a line like this:

filter(lambda x: x == 1, [1, 1, 2])
Pylint is showing a warning:
W:  3: Used builtin function 'filter'
Why is that? is a list comprehension the recommended ...

21. Python - functions being called inside list bracket. How does it work?    stackoverflow.com

I was looking for an algorithm to replace some content inside a list with another. For instance, changing all the '0' with 'X'. I found this piece of code, which works:

 list ...

22. Passing a list of values to a function    stackoverflow.com

Sorry for such a silly question, but sitting in front of the comp for many hours makes my head overheated, in other words — I'm totally confused. My task is to ...

23. python function list chained executing?    stackoverflow.com

In python I defined functions:

def foo_1(p): return p + 1
def foo_2(p): return p + 1
def foo_3(p): return p + 1
def foo_4(p): return p + 1
def foo_5(p): return p + 1
I need ...

24. How to retrieve the list of exceptions of a function or a method    stackoverflow.com

How can I have a clean list of exceptions that a standard function/method can raise ? Without that, how can I anticipate the behavior of a function ? Thanks.

25. Basic python. How to forbid functions to change the list?    stackoverflow.com

>>> def test():
...    a.remove(1)
>>> a = [1,2]
>>> test()
>>> print a 
[2]
Why does a equal [2] rather than [1,2]?

26. Python - use list as function parameters    stackoverflow.com

How can I use a Python list (e.g. params = ['a',3.4,None]) as parameters to a function, e.g.:

def some_func(a_char,a_float,a_something):
   # do stuff

27. Refactoring a python function so that it can take any sized list    stackoverflow.com

How can I make this function take as input an arbitrary list size?

def ugly_function(lst):
    for a in lst[0]:
        for b in ...

28. Calltips/Docstring while viewing function list?    stackoverflow.com

I just recently switched to Komodo for Python programming, and I'm loving it so far. I love how if I type a function name, followed by the open-paren (, it ...

29. call list of function using list comprehension    stackoverflow.com

can I call a list of functions and use list comprehension?

def func1():return 1
def func2():return 2
def func3():return 3

fl = [func1,func2,func3]

fl[0]()
fl[1]()
fl[2]()
I know I can do
for f in fl:
   f()
but ...

30. using functions to display numbers in a list    stackoverflow.com

I have a list of numbers and I have to use a function to display them in celsius, they are in fahrenheit now.

nums = [30,34,40,36,36,28,29,32,34,44,36,35,28,33,29,40,36,24,26,30,30,32,34,32,28,36,24,32]
def fahrenToCel(c):
    c ...

31. Help with understanding list function    stackoverflow.com

When I type the following into the interpreter I get the desired output behavior:

>>> x = (7, 2, 1, 1, 6, 2, 1, 2, 1, 2, 2, 6)
>>> y = list(x)
>>> ...

32. Feeding a List of Lists into a function    stackoverflow.com

I have a multi-dimensional array that I am trying to feed into difflib.get_close_matches(). My array looks like this: array[(ORIGINAL, FILTERED)]. ORIGINAL is a string, and FILTERED is the ORIGINAL string with common ...

33. Python : function inside list comprehension - is it evaluated multiple times    stackoverflow.com

Which one's a better way of doing list comprehension in python (in terms of computation time & cpu cycles). In example (1) is the value f(r) evaluated in each iteration or ...

34. Display a list of user defined functions in the Python IDLE session    stackoverflow.com

Is it possible to display a list of all user functions in the IDLE session? I can see them popping up in the autocomplete, so maybe there is other way to just ...

35. How to pass List as an argument to a function in threading.Timer    stackoverflow.com

How to pass a list as an argument to function in threading.Timer(...) ? Please see the following code. I would like to pass nb[] as an argument

nb=['192.168.1.2', '192.168.1.3', '192.168.1.4']
ping_thread = threading.Timer(12.0, pingstarter, ...

36. 'LIKE' function for Lists    stackoverflow.com

Is there any equivalent 'LIKE' function(like in MySQL) for lists. for example; This is my list:

abc = ['one', 'two', 'three', 'twenty one']
if I give the word "on", it should print the matching ...

37. Passing function's lists with its parameter as a parameter    stackoverflow.com

I want to pass function's list along with its parameters as a parameter in another function using Python. I know it is possible to pass function as a parameter, but is it ...

38. How come my function is only looping through three elements within my list    stackoverflow.com

I am trying to loop through all the elements (8 of them) in my list, but my function is only providing me with 4 of them. This is for an application ...

39. Python function long parameter list    stackoverflow.com

I'm looking for the best way to give a list of arguments to my function :

def myFunc(*args):
    retVal=[]
    for arg in args:
    ...

40. Sort python list by function    stackoverflow.com

I have a function that takes an object as an argument and gives me a number. I wish to use this number as the key to sort my list. If I were ...

41. modified a given list inside a function    stackoverflow.com

i would like to assign new values to the list i pass to my functions. At the case of get_p_values it works fine, but at `read_occupation' not (I get as an ...

42. Python: What am I doing wrong?    stackoverflow.com

I want to get this function to work:

def getEvenNumbers (numbers):

    bo = []
    for num in numbers:
         ...

43. Get function given a list of values    stackoverflow.com

Is there a way that I can give python a list of values like [ 1, 3, 4.5, 1] and obtain a function that relates to those values? like y = ...

44. Python: can function be defined inside of another function's argument list?    stackoverflow.com

Is there a way to achieve something like this in python?

another_function( function(x) {return 2*x} )

45. Python: expand list to function arguments    stackoverflow.com

Ok, stupid python question: Is there syntax that allows you to expand a list into the arguments of a function call? Example:

# trivial example function, not meant to do anything ...

46. pass list of iterables to itertools function    stackoverflow.com

i am using the itertools.product function. i have a 2-deep nested list, which is a list of iterables. i want to pass this to product function dont know how to ...

47. Python - product in-built function    stackoverflow.com

I've been looking through a tutorial and book but I can find no mention of a built in product function i.e. of the same type as sum(), but I could not ...

48. Python list functions    stackoverflow.com

Mind you that python is my first language and I am a student but this isn't homework, I was just hoping someone could show me something I am curious about I know ...

50. List function    bytes.com

51. Limit list of values that can be passed to a function    python-forum.org

Hi guys, I'm writing a Python class. his class has a function in it which accepts only one parameter. def find_content(content_type): .. .. .. .. I would like to limit the list of values that can be passed to the function. The value of content_type can be VIDEO, AUDIO, or IMAGE. What i currently do is let the user pass anything ...

52. Pass list of args to function with 'getattr'    python-forum.org

Hi, I use logging module in an application, and the handler to use for logging is specified in a configuration file. So in my script, I don't know which handler it's going to be used, so I use getattr to call the function to create the instance of the handler, e.g. handler= getattr(logging,opts['handler'])(opts['args']) where 'opts' is a dict with the configuration ...

53. turning a list into function arguments    python-forum.org

54. Adding a function to a list?    python-forum.org

What kind of operation do you do with each checkbox? If it's just assigning a value, etc... Try this: Build a dictionary where keys are checkbox IDs (or checkboxes themselves, they should be hashable) and values being the value assigned. Then you can simply grab a value based on what checkbox was clicked. Another way might be to ignore checkbox events ...

55. creating a list of values generated from a function    python-forum.org

creating a list of values generated from a function by cvani Wed Aug 03, 2011 7:01 am Hi, I am trying to create a list of p_u values here. But it doesn't work. I can't figure out what mistake I have made. These functions would be called number of times depending on how many times the calculation is needed. But ...

56. Calling on a list of functions    python-forum.org

def D_theta1(t,theta1,theta2,w1,w2): print(w1) def D_theta2(t,theta1,theta2,w1,w2): print(w2) def D_w1(t,theta1,theta2,w1,w2): return (-g*3*math.sin(theta1)-g*math.sin((theta1-2*theta2)) -2*math.sin((theta1-theta2))*((w2**2) + ...

57. Lists into Functions    python-forum.org

I need to write code that takes an undetermined number of scores from the user until they type "done," computes the highest, lowest, and average scores. I'm supposed to use a loop for the user input, then pass the high/low/avg to each function. It's for an online class, and I think I get the individual aspects of it, but I can't ...

58. Lists/Functions    python-forum.org

Lists/Functions by marcaake Mon Jul 18, 2011 3:36 pm I need to write code that takes an undetermined number of scores from the user until they type "done," computes the highest, lowest, and average scores. I'm supposed to use a loop for the user input, then pass the high/low/avg to each function. It's for an online class, and I think ...

59. How can I expand Args list to function parameter list?    python-forum.org

Lets say I have a list: args = [1, 3] And I have the following method: def TestFunc(foo, bar) pass If I try to call TestFunc(args) I will get an error because python wants two parameters instead of one. Is there a way I can expand the parameter list so that I can call my function? Anthony

60. Need som list functions    python-forum.org

from BeautifulSoup import BeautifulSoup import urlib2 imporrt urlen listOfUrls = urlen.getUrl() #import urls def returnstatment() bolag0 = urlib2.urlopen(listOfUrls[0]) start0 = bolag0.find('
Aktie+/-+/- %KöpSäljSenastHögstLägstAntalTidBev.lista
Köp Sälj 

61. List functions - Get from net and put it in a list.    python-forum.org

Hi! I got a problem with some lists. I need functions to make it's right, but i don't know what function i will take? Help? Code: Select all import urllib2 import sys, os, signal import urlen username = raw_input('MoneyMaker login password?: ') if username == "hello": print "Welcome to the MoneyMaker \nMoneyMaker is ON..." else: ...

62. Function to list Divisors and Common Even Divisors    python-forum.org

Function to list Divisors and Common Even Divisors by Adi7 Tue Mar 22, 2011 9:12 am My objective is as follows: In the main section of the program, you will prompt the user for the two integers to use. To determine the divisors of an integer, n, you will have a function that receives an integer but does not ...

63. List of numbers for which I need to preform various function    python-forum.org

First time post, so bear with me if these questions are simple to solve. I am not at all familiar with Python language and hoping someone can help me out. I have a list of 7 numbers. I need to write a program that will do the following things: 1. Display the numbers in ascending order. 2. Display the numbers in ...

65. functions that appends to list    python-forum.org

I'm reading through these tutorials and this is confusing me. I create two types of list one initialized to None say for instance b_list = None. then another c_list = [] an empty list this block of text is taken from this site: http://python.net/~goodger/projects/pyc ... -variables //// Default Parameter Values This is a common mistake that beginners often make. Even more ...

66. Sorting lists by a specific field with sort function    python-forum.org

Sorting lists by a specific field with sort function by ep123 Sat Mar 20, 2010 12:55 pm Hi I have created a program which takes in events and saves them to file then loads them up and displays each separate event on a separate line with all fields for each single event on one line with tabs between each of ...

68. Passing a list with a default value in a function    python-forum.org

when you define a function, everything in the signature (not the function body) is evaluated and "bound" in the scope directly outside of the function (in this case, the global scope). That means that when you use a mutable object - like a list - in a signature, for each call to the function the same object will be used. So ...

70. how do i build a list from results of an iterrateve function    python-forum.org

if i have a list and i want to work though it with a function, how do i output the results into a new list? i'm getting messy things happening with lots of seperate print things, i can't keep working with the output very well. just as an example, if i want to double all the numbers in a list of ...

71. Using List in functions    python-forum.org

I'm trying to write 3 functions. 1) to read the data from a file into a list. 2) to sort the list . 3) to write the list to a file. Do I want to pass a list or return a list. Function 1) would create the list but how does Function 2 and Function 3 get the list? Can someone ...

72. How to call functions with argument lists    python-forum.org

>>> myargs={'x':1., 'a':2., 'b':3.} >>> a=myargs.copy() >>> a.pop('a') 2.0 >>> lambda z:f(z, **a) at 0x758b0> >>> (lambda z:f(z, **a))(1.) Traceback (most recent call last): File "", line 1, in File "", line 1, in TypeError: f() got multiple values for keyword argument 'x' >>>

73. lists as function arguments question    python-forum.org

import random suits = [ 'clubs', 'hearts', 'diamonds', 'spades' ] values = [ '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A' ] deck = [] def initDeck(myDeck): myDeck[:] = [ (x,y) for x in values for y in suits ] def easyShuffle(myDeck): random.shuffle(myDeck) initDeck(deck) print "fresh deck: ",deck,'\n\n' easyShuffle(deck) print ...

74. Lists tied to their function calls now?    python-forum.org

Well, I guess you learn something new everyday ;) I've been programming with Python for 5 years and always assumed that any changes made to anything sent to a function were only local unless you declare the variable global. I thought I read it in a book back when I learned it, but I can't say for sure... and since you ...

75. List and function scope    python-forum.org

Hello, I was learning python at home and I have this quick question, perhaps clarification: Code: Select all #!/usr/bin/python #global vars def function1(): global g_var1 print g_var1 g_var1 = "Changing the global var" print g_var1 global g_list ...

76. List as function argument?    python-forum.org

16 print type(seq) ---> 17 if seq[0]==0: 18 if k==0: 19 integralen=Trapetz(a,b,h) : 'int' object is unsubscriptable ...

77. Getting list of functions in parent namespace    python-forum.org

Thanks for the response. More specific? Sure. I want one method in my module that will call all the other functions in the module, with out actually knowing what the other functions are. If I call dir() from within a method it list's its namespace. I want the parent of the method's namespace. For example: If we have module1 with the ...

78. Changes to lists declared in function header    python-forum.org

default argument values are bound to the function when the function is defined. it isn't a global variable because it isn't in globals() -- it's in listTest.func_defaults. i don't know why the dev team chose to make arguments append to the list instead of re-bind it, but that's what happens. yeah, i think it is a wart, but i really don't ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.