I'm sorry if this is a question answered elsewhere. Searching through Google and Stackforum I didn't find anything from which I could extrapolate the answers; but I feel like part of that is me.
I'm trying to work out lambdas as a concept, and as part of that I'm kinda looking for ways to use it.
SO, if this is a colossally stupid thing to do with lambda from a function standpoint, feel free to let me know and explain. But either way, I still want to know the answer/still want to know how to do this with the python language.
So, for testing purposes I have:
my_test = 'test_name'
testlist = ['test_name', 'test_name_dup', 'test_name_dup_1', 'test_name_dup_3']
I'm looking to use lambda to create one function that loops through and returns the first test_name_# that isn't in the testlist. The functionality will eventually be applied to filenames, but for testing purposes I had to get away from actually reading the filenames--gave me too many more ways to mess something up.
But my_test has to be able to change, and the test list will be a list of filepaths.
So, I'm looking for a function like:
new_name = lambda x: my_test + '_' + str(x)
But the initial value should be x = 1, and it should continue until new_name is not in testlist. Seems like:
bool(new_name not in testlist)
might be something work with.
But I can't figure out a way to set the initial x to 1, and have it loop through with (x+1) until the bool is true.
I know this is possible as I've found some CRAZY lambda examples out there that are looping through lines in a file. I just couldn't quite make sense of them (and didn't have any way to play with them as they were dealing with things outside my programming level.
On a related note, could I add values to the beginning of this loop? (i.e. can I have it check for test_name, then test_name_dup, then test_name_dup_#)?
Thanks in advance for the help! Lambdas (while very cool) totally mess with my head.
lambdaexamples may just be bad examples aslambdas are not meant for lots of code because they make code unreadable and using a normal function is a lot better in most situations.