0

What is the equivalent of vector<double> (of C++) in Python ?

Hi everyone! I am trying to re-write the same program that I made in C++ but in Python. In a function I used vector<double> for get its size(), its back() and its end(). And I would like to know what the best function or technique, just the equivalent of those in Python. Thanks to all that would answer me 😊

27th Mar 2020, 8:55 AM
Siyam
Siyam - avatar
4 Réponses
+ 1
Vector has `size`, `front` and `back` method. But I'm not sure about `end`. Did you mean vector iterator? I was thinking a Python `list` maybe was what you want. But just for the sake of clarity, I'd prefer to see your C++ code first. So I suggest you to attach the code link in the thread Description 👍 Follow this guide just in case you didn't know how to share links 👇 https://www.sololearn.com/post/75089/?ref=app
27th Mar 2020, 9:15 AM
Ipang
+ 1
This is my code Ipang
27th Mar 2020, 1:15 PM
Siyam
Siyam - avatar
+ 1
Siyam There are some problems with the C++ code. Please fix the problems, currently the code is not running. Can you elaborate about what the code should do? I have no idea what the code is supposed for. Need more info sspecially about the `calc` method. I edited your code and added a few comments. https://code.sololearn.com/cdhT442T41R1/?ref=app
27th Mar 2020, 3:19 PM
Ipang
0
#include <iostream> #include <cstdio> #include <cstdlib> #include <vector> #include <iomanip> using namespace std; class temperature { public: temperature(); ~temperature(); void calc(unsigned int); protected: private: vector<double> _queue; double _g; int switches; } temperature::temperature() { this->switches = 0 } temperature::temperature() { } void calc(unsigned int period) { if (this->_queue.size() <= period){ return; } this->_g = 0; for (size_t counter = this->_queue.size() - period; counter != this->_queue.size(); counter++) { double tmp = this->_queue[counter] - this->[counter - 1]; this->_g += (tmp > 0 ? tmp : 0); } this-> /= period; } int main() { return 0; }
27th Mar 2020, 1:14 PM
Siyam
Siyam - avatar