This file contains 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
""" | |
Problem Statement | |
Given a set of numbers M and another number k | |
Find if there exists 3 numbers a,b,c in M such that | |
a+b+c = k | |
in complexity O(N^2) | |
Solution | |
This code solves the problem in O(N^2). However, following assumptions had been made | |
Set comprises of positive integers. | |
Note - the code can be customized to handle negative numbers and decimals |
This file contains 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
<table> | |
<tbody> | |
<tr> | |
<td>{{ first_name }}</td><td>{{ middle_name}}</td><td>{{ last_name }}</td> | |
</tr> | |
</tbody> | |
</table> |
This file contains 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
class NameWidget(forms.MultiWidget): | |
""" | |
Custom widget for Custom Field Name Field | |
""" | |
def __init__(self): | |
widgets = ( | |
forms.TextInput(attrs={}), | |
forms.TextInput(attrs={}), | |
forms.TextInput(attrs={}) | |
) |
This file contains 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
class AddressField(forms.MultiValueField): | |
""" | |
Custom field to take user inputs of Address | |
""" | |
def __init__(self, country_choices, city_choices, locality_choices, attrs=None): | |
self.widget = AddressWidget(country_choices,city_choices,locality_choices) | |
fields = (forms.CharField(label=_('Address Line 1'), max_length=100), forms.CharField(label=_('Address Line 2'), max_length=100), forms.ChoiceField(label=_('Country'), choices=country_choices), forms.ChoiceField(label=_('City'), choices=city_choices), forms.ChoiceField(label=_('Locality'), choices=locality_choices)) | |
super(AddressField, self).__init__(fields, required=False) |
This file contains 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
class AddressWidget(forms.MultiWidget): | |
""" | |
Custom widget for Custom Field AddressField | |
""" | |
def __init__(self, country_choices, city_choices, locality_choices, attrs=None): | |
widgets = (forms.TextInput(), forms.TextInput(), forms.Select(attrs=attrs, choices=country_choices), forms.Select(attrs=attrs, choices=city_choices),forms.Select(attrs=attrs, choices=locality_choices), forms.TextInput()) | |
super(AddressWidget, self).__init__(widgets, attrs) | |
def decompress(self, value): | |
if value: |