function sum(a, b) {
return a + b
}
let sum = (a, b) => {
return a + b
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| https://stackoverflow.com/questions/5389507/iterating-over-every-two-elements-in-a-list | |
| https://stackoverflow.com/questions/5764782/iterate-through-pairs-of-items-in-a-python-list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| In [69]: package_details = ['Weight:', 2, 'Weight:', 4 ] | |
| In [71]: package_details[::2] | |
| Out[71]: ['Weight:', 'Weight:'] | |
| In [72]: package_details[1::2] | |
| Out[72]: [2, 4] | |
| In [73]: total_weight = sum(v for k, v in zip(package_details[::2], package_details[1::2]) if k == 'Weight:') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| In [50]: students =[ | |
| {'name': 'Paul Allen', 'class': 'Science', 'grade': 'A'}, | |
| {'name': 'paul allen', 'class': 'Math', 'grade': 'C'}, | |
| {'name': 'Bob Lewis', 'class': 'Science', 'grade': 'D'}, | |
| {'name': 'Bob Lewis', 'class': 'math', 'grade': 'b'}, | |
| {'name': 'bob Lewis', 'class': 'History', 'grade': 'f'} | |
| ] | |
| In [52]: sorted(students) | |
| --------------------------------------------------------------------------- |
# views.py
def display(request):
context = {'hi': 'bob'}
return render(request, 'firstApp/index.html', context)<!-- index.html -->
{{ hi }}python3 manage.py startapp polls
polls/templates/polls/index.html
polls/static/polls/css/style.css polls/static/polls/images/hi.jpg
# views.py
def display(request):# models.py
class Employee(models.Model):
firstName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
salary = models.FloatField()
email = models.CharField(max_length=30)