Tagged Questions
-1
votes
4answers
39 views
Python function which can transverse a nested list and print out each element
For example if have the list [[['a', 'b', 'c'], ['d']],[['e'], ['f'], ['g']]] the function should print out 'a' 'b' 'c' ...ect. on separate lines.It needs to be able to do this for any variation in ...
2
votes
3answers
75 views
Python Function Return
If I want to return more that one variable from a function in Python I have been doing the following:
def foo():
firstName = 'Bob'
lastName = 'Jones'
return [firstName, lastName]
Then ...
2
votes
2answers
52 views
Python For Looping, Function Problems
I'm trying to create a little Guess The Flag game using Pygame and Python, but there's a problem with some for looping and and functions I've created. I'm relatively new to Python, and sometimes, I ...
-1
votes
3answers
40 views
Python function that is supposed to take a certain file and print out the occurrences of a certain part of the file
For example, if I take this file: http://vlm1.uta.edu/~athitsos/courses/cse1310_summer2013/assignments/assignment7/albums.txt
I need the function to count each band and the number of times they are ...
2
votes
2answers
57 views
Python dict call function as value
I'm creating a dict in python using returned json.
one of the values I want to be a shortuuid, so I put a function as the value.
I want that function called and the value replaced with what that ...
3
votes
4answers
67 views
Optimizing a python function with numpy arrays
I have been trying to optimize a python script I wrote for the last two days. Using several profiling tools (cProfile, line_profiler etc.) I narrowed down the issue to the following function below.
...
0
votes
1answer
54 views
How do I stop and repeat a function?
How do I stop the program if value is > 10 or < 0 and display Error and then display the question again?
import random
while True:
value = int(input("Enter the amount of questions would ...
1
vote
4answers
72 views
Python custom function
I have been working at learning Python over the last week and it has been going really well, however I have now been introduced to custom functions and I sort of hit a wall. While I understand the ...
-1
votes
1answer
8k views
python: local variable referenced before assignment error
I am completing a text based game for an intro to python class. It is not complete but I was working on the main_menu function and the functions called within the main_menu function when I ran into ...
10
votes
2answers
1k views
What method attributes are used in Django?
Under the documentation for ModelAdmin.list_display it describes a few ways to configure a method/function for usage and display in an admin's list view:
admin_order_field (describes which field in ...
5
votes
3answers
1k views
What is the benefit to define a function in a function in python?
I encountered this piece of python code (pasted below) on effbot and I was wondering:
Why defining a function within a function?
import re, htmlentitydefs
##
# Removes HTML or XML character ...
6
votes
3answers
2k views
What is the best way to exit a function (which has no return value) in python before the function ends (e.g. a check failes)?
Let's assume an iteration in which we call a function without a return value. The way I think my program should behave is explained in this pseudocode:
for element in some_list:
foo(element)
def ...
14
votes
8answers
14k views
Function parameter types in Python
Unless I'm mistaken, creating a function in Python works like this:
def my_func(param1, param2):
# stuff
However, you don't actually give the types of those parameters. Also, if I remember, ...
8
votes
6answers
7k views
Python: return the index of the first element of a list which makes a passed function true
the list.index(x) function returns the index in the list of the first item whose value is x.
is there a function, list_func_index(), similar to the index() function that has a function, f(), as a ...
35
votes
6answers
9k views
Ignore python multiple return value
Say I have a Python function that returns multiple values in a tuple:
def func():
return 1, 2
Is there a nice way to ignore one of the results rather than just assigning to a temporary ...