Skip to content

Instantly share code, notes, and snippets.

@BurcakAsal
Created October 16, 2015 06:17
Show Gist options
  • Save BurcakAsal/3478a253b2c5082924ef to your computer and use it in GitHub Desktop.
Save BurcakAsal/3478a253b2c5082924ef to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def func_max(list):\n",
" \n",
" max=list[0]\n",
" \n",
" for i in range(1,len(list)):\n",
" if(list[i]>max):\n",
" max=list[i]\n",
" return (max)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def func_nthmax(n,list):\n",
" \n",
" \n",
" \n",
" for i in range(0,n-1):\n",
" list.remove(func_max(list))\n",
" \n",
" return(func_max(list))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def mod_nm(number,divider):\n",
" while(number>=divider):\n",
" number-=divider\n",
" \n",
" return number\n",
" \n",
"\n",
"line_number = int(raw_input('Enter key number:'))\n",
"\n",
"myfile = open(\"new_file.txt\",\"w\")\n",
"\n",
"for i in range(1,line_number+1):\n",
" key = i*10 \n",
" myfile.write(str(key)+' '+str(mod_nm(key,7))+'\\n')\n",
" \n",
"myfile.close() \n",
"\n",
"new_dict = {}\n",
"\n",
"myfile = open(\"new_file.txt\",\"r\")\n",
"\n",
"for line_of_text in myfile:\n",
" word_list = line_of_text.split()\n",
" if(len(word_list)>0):\n",
" new_dict[int(word_list[0])] = int(word_list[1]) \n",
"for e_key in new_dict.keys():\n",
" print(str(e_key)+' '+str(new_dict[e_key])+'\\n')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def fibonacci_dict(n,dict):\n",
" dict[0]=0;\n",
" dict[1]=1;\n",
" \n",
" for i in range(2,n+1):\n",
" dict[i]=dict[i-1]+dict[i-2]\n",
" return dict\n",
" \n",
"#function demo \n",
"fib_dict={} \n",
" \n",
"fib_dict=fibonacci_dict(7,fib_dict)\n",
"\n",
"print(fib_dict) "
]
}
],
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment