BASIC vs Python
Gregor Horvath
g.horvath at gmx.at
Fri Dec 17 07:09:31 EST 2004
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?
VB6 Code:
Sub xy()
Dim lst1 As New Collection
Dim lst2 As New Collection
lst1.Add "ab", "ab": lst1.Add "ac", "ac": lst1.Add "ba", "ba": lst1.Add
"bb", "bb": lst1.Add "bc", "bc"
lst2.Add "ac", "ac": lst2.Add "ab", "ab": lst2.Add "bd", "bd": lst2.Add
"cb", "cb": lst2.Add "bb", "bb"
For Each item In lst1
If ColHasKey(lst2, item) Then Debug.Print "in:" & item
Next
For Each item In lst1
If Not ColHasKey(lst2, item) Then Debug.Print "not in:" & item
Next
End Sub
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
More information about the Python-list
mailing list