Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python vector
#1
Pyvec is a working incomplete pure python "implementation" of c++ vector wich supports iterators (begin() end()) and more source code github I'm waiting your comments, feel free to open an issue, feel free to create a pull request

from vector import *

v1 = Vector()

# Add 3 elements to vector
v1.push_back("a")
v1.push_back("b")
v1.push_back("c")

print(v1)
print("")

# ['a', 'b', 'c']

assert(v1.empty() == False)

# Remove last element from vector
v1.pop_back()

print(v1) 
print("")
#['a', 'b']

# Add element at specifiec possition
pos = 0
element = "e"
v1.insert(pos, element)

print(v1)
print("")

assert(len(v1) == 3)


# Print all elements using begin() & end()

v = v1.begin()

while v != v1.end():
    print(v[0])
    v +=1



#e
#a
#b


# clear vector 
v1.clear()

print("")
print(v1) 
# []

assert(v1.empty() == True)
Reply


Messages In This Thread
Python vector - by cvsae - Jul-27-2019, 10:21 PM
RE: Python vector - by ThomasL - Jul-28-2019, 06:38 AM
RE: Python vector - by cvsae - Jul-28-2019, 02:56 PM
RE: Python vector - by Gribouillis - Jul-28-2019, 05:29 PM
RE: Python vector - by ndc85430 - Aug-25-2019, 06:12 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020