[Tutor] Novice Python Question
kent37 at tds.net
Tue Jul 1 14:40:11 CEST 2008
On Tue, Jul 1, 2008 at 7:51 AM, S Potter <f8lcoder at hotmail.com> wrote:
> Question 1.)
> I have dictionary or list containing multiple instances 'duplicate
> entries' of the same information. Lets say it's a list of addresses and list
> item i contains city values equal to 'Albany' .
> I am using a second list of one element to provide my filter criteria.
> This list contains only cities with no duplicate entries.
> How do I filter my first list based upon the selected position or a
> variable equal to the value of the selected position from my second list?
It would help to see more specific examples of the data you have and
the desired result, but in general a list comprehension is the easiest
way to filter a list.
> Question 2.) If I assign a value to a variable x = "MyVlaue"
> How do I put the value of x into a list?
> I would think it would be something like:
> But I'm not getting the results I expect.
> This would probably be considered
> macro-substitution in other languages but I cannot find reference to this in
The value of x is the string "MyVlaue", is that what you want? If so
what you are doingis close, you can use simply [x] to create a list
containing the value of x. Or do you want the value of the variable
named MyVlaue? In that case you probably should use a dictionary to
hold the value rather than a named variable.
More information about the Tutor