Skip to content

Instantly share code, notes, and snippets.

@Bhupesh-V
Last active March 12, 2020 06:23
Show Gist options
  • Save Bhupesh-V/c2fa0232673fa42dcc18b0ad7c75ac73 to your computer and use it in GitHub Desktop.
Save Bhupesh-V/c2fa0232673fa42dcc18b0ad7c75ac73 to your computer and use it in GitHub Desktop.

C++ Alternatives to Python

  1. startswith()
std::string s = "tititoto";
if (s.rfind("titi", 0) == 0) {
  // s starts with prefix
}
  1. collections,Counter()
	std::vector<int> v = { 7, 2, 2, 4, 3, 2, 6 };
	int val = 2;

	int freq = std::count(v.begin(), v.end(), val);
	std::cout << "Element " << val << " occurs " << freq << " times";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment