Best Python code snippet using slash
Atom.py~
Source:Atom.py~  
...51#self._hash52	def set(self, name, resid ):53		self.name=name.strip()54		self.resid=resid55		self._compute_id()56		return self57	def _compute_id(self):58		assert len(self.name)<=5, 'Atom-Names with more than 5 characters are not supported due to ID encoding scheme'59		self._id=060		factor=161		for c in self.name:62			self._id+=ord(c)*factor63			factor*=25664		self._id+=self.resid*(256**5)65		self._hash=None66	def match_fuzzy( self, other ):67		if self.resid != other.resid: return False68		if self.name[0:2]=='QQ' or	other_name[0:2]=='QQ':69			return self.methyl_name(2)==other.methyl_name(2)70		if self.name[0]=='Q' or other.name[0]=='Q':71			return self.methyl_name(1)==other.methyl_name(1)72		return self==other73		#for a HB2 return QB, ...74	def methyl_name(self,depth=1):75		if self.res3_type:76			if self.res3_type=='ILE':77				if self.name[0:3]=='HD1':78					return 'QD1'79				if self.name[0:3]=='HG2':80					return 'QG2'81			elif self.res3_type=='LEU':82				if self.name[0:2]=='HD':83					return 'QD'+self.name[2]84			elif self.res3_type=='VAL':85				if self.name[0:2]=='HG':86					return 'QG'+self.name[2]87			elif self.res3_type=='ALA':88				if self.name[0:2]=='HB':89					return 'QB'90			elif self.res3_type=='MET':91				if self.name[0:2]=="HE":92					return 'QE'93			elif self.res3_type=='THR':94				if self.name[0:3]=='HG2':95					return 'QG2'96			elif self.res3_type=='LYS':97				if self.name[0:2]=='HZ':98					return 'QZ'99			return self.name100		name=self.name101		if self.element!='H' or depth==0: return name102		if name=='H': return name103		if name=='HA': return name104		if name[0:depth]=='Q'*depth: return name105		if depth>1:106			s=self.methyl_name(depth-1)107		else:108			s=name[1:]109		return 'Q'+s[0:-1]110	def methyl_atom( self ):111		return Atom( self.methyl_name(), self.resid, res_type=self.res3_type, elem=self.element, types=self.types )112	def set_resid(self,resid):113		self.resid=resid114		self._compute_id()115	def set_name(self,name):116		self.name=name117		self._compute_id()118def unit_test():119	a1=Atom('HB3',1)120	a2=Atom('QB',1)121	a3=Atom('HD12',1)122	a4=Atom('QQD',1)123	a5=Atom('H',1)124	assert a1.methyl_name()=='QB'125	assert a3.methyl_name()=='QD1'126	assert a3.methyl_name(2)=='QQD', 'wrong result: %s'%a3.methyl_name(2)127	assert a4.methyl_name(1)=='QQD'128	assert a4.methyl_name(2)=='QQD'129	assert a5.methyl_name()=='H'130	assert a1.match_fuzzy(a2)131	assert a3.match_fuzzy(a4)...solution.py
Source:solution.py  
...11        for line in file:12            yield line.strip()13def _decode_seat_id(seat: str) -> int:14    row, column = _decode_seat_row_and_column(seat)15    return _compute_id(row, column)16def _decode_seat_row_and_column(seat: str) -> tuple[int, int]:17    return _decode_row(seat), _decode_column(seat)18def _decode_row(seat: str) -> int:19    return _convert_binary_number_string_to_int(seat[:7].replace("F", "0").replace("B", "1"))20def _decode_column(seat: str) -> int:21    return _convert_binary_number_string_to_int(seat[-3:].replace("R", "1").replace("L", "0"))22def _convert_binary_number_string_to_int(binary: str) -> int:23    return int(binary, 2)24def _compute_id(row: int, column: int) -> int:25    return row * COLUMNS + column26def _find_free_seat_id(seats: Iterator[str]) -> int:27    row, column = _find_free_seat_row_and_column(seats)28    return _compute_id(row, column)29def _find_free_seat_row_and_column(seats: Iterator[str]) -> tuple[int, int]:30    occupied = _create_occupied_array(seats)31    first_row = _find_first_occupied_row(occupied)32    return next(33        (row, column) for row in range(first_row + 1, ROWS) for column in range(COLUMNS) if not occupied[row][column]34    )35def _create_occupied_array(seats: Iterator[str]) -> list[list[bool]]:36    occupied = [[False for _ in range(COLUMNS)] for _ in range(ROWS)]37    for seat in seats:38        row, column = _decode_seat_row_and_column(seat)39        occupied[row][column] = True40    return occupied41def _find_first_occupied_row(occupied: list[list[bool]]) -> int:42    return next(row for row in range(ROWS) if any(occupied[row]))...hr_employee.py
Source:hr_employee.py  
2from openerp.osv import fields, osv3class cbpo_hr_employee4(osv.osv):4    _inherit="hr.employee"5    #6    def _compute_id(self, cr, uid, ids, fieldnames, args, context=None):7        res = dict.fromkeys(ids, 0)8        count_id=09        for obj in self.browse(cr, uid, ids, context=context):10            if(obj.identification_id):11                count_id=len(obj.identification_id)12            if(count_id==0):13                res[obj.id] = ''14            elif(count_id!=14):15                raise osv.except_osv('Error!  Identification ID!','Identification ID : Must Be 14 characters. \nNot  '+str(count_id)+' characters.')16                print " Error!  Identification ID! "17            else:18                res[obj.id] = 'OK'19        return res20    _columns = {...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
