Skip to content

Instantly share code, notes, and snippets.

@anshulkgupta93
Created January 7, 2016 18:25
Show Gist options
  • Save anshulkgupta93/12487b5abef82b20c3eb to your computer and use it in GitHub Desktop.
Save anshulkgupta93/12487b5abef82b20c3eb to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import re"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"num=[\"$50000\",\"$50,000\",\"50,000\",50000,\"50000\"]\n",
"for i,value in enumerate(num):\n",
" num[i]=re.sub(r\"([$,])\",\"\",str(value))\n",
" num[i]=int(num[i])"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[50000, 50000, 50000, 50000, 50000]\n"
]
}
],
"source": [
"print num"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"50000.0\n"
]
}
],
"source": [
"import numpy as np\n",
"print np.mean(num)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"names=[\"Ajay\",\"Vijay\",\"Rajay\",\"Jayesh\"]"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"True\n",
"True\n",
"False\n"
]
}
],
"source": [
"for name in names:\n",
" print bool(re.search(r'(jay)', name))\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment