BASIC vs Python
Peter Otten
__peter__ at web.de
Fri Dec 17 08:47:08 EST 2004
Gregor Horvath wrote:
> Peter Otten wrote:
>
>> May you could give us an idea of the current state of basic affairs then
>> by translating the following example snippet:
>
> yes you can do it in VB6, but pythons lists and dictionarys are superior
> to those built in in VB and I think to those in most other languages.
>
>>
>> It's me wrote:
>>
>>
>>>I saw this code from an earlier post:
>>>
>>>lst1 = ["ab", "ac", "ba", "bb", "bc"]
>>>lst2 = ["ac", "ab", "bd", "cb", "bb"]
>>>dct1 = dict.fromkeys(lst1)
>>>print [x for x in lst1 if x not in dct1]
>>>print [x for x in lst1 if x in dct1]
>
> I think line3 should be
>
> >>dct1 = dict.fromkeys(lst2)
>
> correct?
Either that or lst2 in the list comprehensions.
> VB6 Code:
[snip]
> Function ColHasKey(col As Collection, item) As Boolean
> On Error GoTo er
> A = col(item)
> ColHasKey = True
> Exit Function
> er:
> If Err.Number = 5 Then
> ColHasKey = False
> Else
> Err.Raise Err.Number
> End If
> End Function
Almost an exception handler ;-)
Thank you for taking the time to show me. I had VB.Net in mind when I wrote
"current state", though.
Peter
More information about the Python-list
mailing list