1597907392

# Python Division: What are division operators in Python 3

The division is a standard mathematical operation in any programming language, and Python is no exception. In Python 2, there is only one kind of division called integer division.

In general, the python definition of division( / ) depended solely on the arguments. For example, in python 2.7, dividing 11/4 was 2 because both arguments were integers.

However, 20.0/7 will generate 2.857142857142857 as output because the arguments were floating-point numbers.

The above definition of ‘/’ often caused problems for applications where data types were used that the author hadn’t expected.

#python

1619518440

## top 30 Python Tips and Tricks for Beginners

Welcome to my Blog , In this article, you are going to learn the top 10 python tips and tricks.

### 8) Check The Memory Usage Of An Object.

#python #python hacks tricks #python learning tips #python programming tricks #python tips #python tips and tricks #python tips and tricks advanced #python tips and tricks for beginners #python tips tricks and techniques #python tutorial #tips and tricks in python #tips to learn python #top 30 python tips and tricks for beginners

1619510796

## Lambda, Map, Filter functions in python

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

Syntax: x = lambda arguments : expression

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map

1619565060

## Ternary operator in Python?

1. Ternary Operator in Python

What is a ternary operator: The ternary operator is a conditional expression that means this is a comparison operator and results come on a true or false condition and it is the shortest way to writing an if-else statement. It is a condition in a single line replacing the multiline if-else code.

syntax : condition ? value_if_true : value_if_false

condition: A boolean expression evaluates true or false

value_if_true: a value to be assigned if the expression is evaluated to true.

value_if_false: A value to be assigned if the expression is evaluated to false.

How to use ternary operator in python here are some examples of Python ternary operator if-else.

Brief description of examples we have to take two variables a and b. The value of a is 10 and b is 20. find the minimum number using a ternary operator with one line of code. ( **min = a if a < b else b ) **. if a less than b then print a otherwise print b and second examples are the same as first and the third example is check number is even or odd.

#python #python ternary operator #ternary operator #ternary operator in if-else #ternary operator in python #ternary operator with dict #ternary operator with lambda

1630743562

## A Wrapper for Sembast and SQFlite to Enable Easy

FHIR_DB

This is really just a wrapper around Sembast_SQFLite - so all of the heavy lifting was done by Alex Tekartik. I highly recommend that if you have any questions about working with this package that you take a look at Sembast. He's also just a super nice guy, and even answered a question for me when I was deciding which sembast version to use. As usual, ResoCoder also has a good tutorial.

I have an interest in low-resource settings and thus a specific reason to be able to store data offline. To encourage this use, there are a number of other packages I have created based around the data format FHIR. FHIR® is the registered trademark of HL7 and is used with the permission of HL7. Use of the FHIR trademark does not constitute endorsement of this product by HL7.

## Using the Db

So, while not absolutely necessary, I highly recommend that you use some sort of interface class. This adds the benefit of more easily handling errors, plus if you change to a different database in the future, you don't have to change the rest of your app, just the interface.

I've used something like this in my projects:

``````class IFhirDb {
IFhirDb();
final ResourceDao resourceDao = ResourceDao();

Future<Either<DbFailure, Resource>> save(Resource resource) async {
Resource resultResource;
try {
resultResource = await resourceDao.save(resource);
} catch (error) {
return left(DbFailure.unableToSave(error: error.toString()));
}
return right(resultResource);
}

Future<Either<DbFailure, List<Resource>>> returnListOfSingleResourceType(
String resourceType) async {
List<Resource> resultList;
try {
resultList =
await resourceDao.getAllSortedById(resourceType: resourceType);
} catch (error) {
return left(DbFailure.unableToObtainList(error: error.toString()));
}
return right(resultList);
}

Future<Either<DbFailure, List<Resource>>> searchFunction(
String resourceType, String searchString, String reference) async {
List<Resource> resultList;
try {
resultList =
await resourceDao.searchFor(resourceType, searchString, reference);
} catch (error) {
return left(DbFailure.unableToObtainList(error: error.toString()));
}
return right(resultList);
}
}
``````

I like this because in case there's an i/o error or something, it won't crash your app. Then, you can call this interface in your app like the following:

``````final patient = Patient(
resourceType: 'Patient',
name: [HumanName(text: 'New Patient Name')],
birthDate: Date(DateTime.now()),
);

final saveResult = await IFhirDb().save(patient);
``````

This will save your newly created patient to the locally embedded database.

IMPORTANT: this database will expect that all previously created resources have an id. When you save a resource, it will check to see if that resource type has already been stored. (Each resource type is saved in it's own store in the database). It will then check if there is an ID. If there's no ID, it will create a new one for that resource (along with metadata on version number and creation time). It will save it, and return the resource. If it already has an ID, it will copy the the old version of the resource into a _history store. It will then update the metadata of the new resource and save that version into the appropriate store for that resource. If, for instance, we have a previously created patient:

``````{
"resourceType": "Patient",
"id": "fhirfli-294057507-6811107",
"meta": {
"versionId": "1",
"lastUpdated": "2020-10-16T19:41:28.054369Z"
},
"name": [
{
"given": ["New"],
"family": "Patient"
}
],
"birthDate": "2020-10-16"
}
``````

And we update the last name to 'Provider'. The above version of the patient will be kept in _history, while in the 'Patient' store in the db, we will have the updated version:

``````{
"resourceType": "Patient",
"id": "fhirfli-294057507-6811107",
"meta": {
"versionId": "2",
"lastUpdated": "2020-10-16T19:45:07.316698Z"
},
"name": [
{
"given": ["New"],
"family": "Provider"
}
],
"birthDate": "2020-10-16"
}
``````

This way we can keep track of all previous version of all resources (which is obviously important in medicine).

For most of the interactions (saving, deleting, etc), they work the way you'd expect. The only difference is search. Because Sembast is NoSQL, we can search on any of the fields in a resource. If in our interface class, we have the following function:

``````  Future<Either<DbFailure, List<Resource>>> searchFunction(
String resourceType, String searchString, String reference) async {
List<Resource> resultList;
try {
resultList =
await resourceDao.searchFor(resourceType, searchString, reference);
} catch (error) {
return left(DbFailure.unableToObtainList(error: error.toString()));
}
return right(resultList);
}
``````

You can search for all immunizations of a certain patient:

``````searchFunction(
'Immunization', 'patient.reference', 'Patient/\$patientId');
``````

This function will search through all entries in the 'Immunization' store. It will look at all 'patient.reference' fields, and return any that match 'Patient/\$patientId'.

The last thing I'll mention is that this is a password protected db, using AES-256 encryption (although it can also use Salsa20). Anytime you use the db, you have the option of using a password for encryption/decryption. Remember, if you setup the database using encryption, you will only be able to access it using that same password. When you're ready to change the password, you will need to call the update password function. If we again assume we created a change password method in our interface, it might look something like this:

``````class IFhirDb {
IFhirDb();
final ResourceDao resourceDao = ResourceDao();
...
try {
} catch (error) {
}
return right(Unit);
}
``````

You don't have to use a password, and in that case, it will save the db file as plain text. If you want to add a password later, it will encrypt it at that time.

### General Store

After using this for a while in an app, I've realized that it needs to be able to store data apart from just FHIR resources, at least on occasion. For this, I've added a second class for all versions of the database called GeneralDao. This is similar to the ResourceDao, but fewer options. So, in order to save something, it would look like this:

``````await GeneralDao().save('password', {'new':'map'});
await GeneralDao().save('password', {'new':'map'}, 'key');
``````

The difference between these two options is that the first one will generate a key for the map being stored, while the second will store the map using the key provided. Both will return the key after successfully storing the map.

Other functions available include:

``````// deletes everything in the general store

// delete specific entry

// returns map with that key
``````

FHIR® is a registered trademark of Health Level Seven International (HL7) and its use does not constitute an endorsement of products by HL7®

## Use this package as a library

### Depend on it

Run this command:

With Flutter:

`` \$ flutter pub add fhir_db``

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

``````dependencies:
fhir_db: ^0.4.3``````

Alternatively, your editor might support or flutter pub get. Check the docs for your editor to learn more.

### Import it

Now in your Dart code, you can use:

``````import 'package:fhir_db/dstu2.dart';
import 'package:fhir_db/dstu2/fhir_db.dart';
import 'package:fhir_db/dstu2/general_dao.dart';
import 'package:fhir_db/dstu2/resource_dao.dart';
import 'package:fhir_db/encrypt/aes.dart';
import 'package:fhir_db/encrypt/salsa.dart';
import 'package:fhir_db/r4.dart';
import 'package:fhir_db/r4/fhir_db.dart';
import 'package:fhir_db/r4/general_dao.dart';
import 'package:fhir_db/r4/resource_dao.dart';
import 'package:fhir_db/r5.dart';
import 'package:fhir_db/r5/fhir_db.dart';
import 'package:fhir_db/r5/general_dao.dart';
import 'package:fhir_db/r5/resource_dao.dart';
import 'package:fhir_db/stu3.dart';
import 'package:fhir_db/stu3/fhir_db.dart';
import 'package:fhir_db/stu3/general_dao.dart';
import 'package:fhir_db/stu3/resource_dao.dart'; ``````

example/lib/main.dart

``````import 'package:fhir/r4.dart';
import 'package:fhir_db/r4.dart';
import 'package:flutter/material.dart';
import 'package:test/test.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

final resourceDao = ResourceDao();

// await resourceDao.updatePw('newPw', null);
await resourceDao.deleteAllResources(null);

group('Playing with passwords', () {
test('Playing with Passwords', () async {
final patient = Patient(id: Id('1'));

final saved = await resourceDao.save(null, patient);

await resourceDao.updatePw(null, 'newPw');
final search1 = await resourceDao.find('newPw',
resourceType: R4ResourceType.Patient, id: Id('1'));
expect(saved, search1[0]);

final search2 = await resourceDao.find('newerPw',
resourceType: R4ResourceType.Patient, id: Id('1'));
expect(saved, search2[0]);

final search3 = await resourceDao.find(null,
resourceType: R4ResourceType.Patient, id: Id('1'));
expect(saved, search3[0]);

await resourceDao.deleteAllResources(null);
});
});

final id = Id('12345');
group('Saving Things:', () {
test('Save Patient', () async {
final humanName = HumanName(family: 'Atreides', given: ['Duke']);
final patient = Patient(id: id, name: [humanName]);
final saved = await resourceDao.save(null, patient);

expect(saved.id, id);

expect((saved as Patient).name?[0], humanName);
});

test('Save Organization', () async {
final organization = Organization(id: id, name: 'FhirFli');
final saved = await resourceDao.save(null, organization);

expect(saved.id, id);

expect((saved as Organization).name, 'FhirFli');
});

test('Save Observation1', () async {
final observation1 = Observation(
id: Id('obs1'),
code: CodeableConcept(text: 'Observation #1'),
effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
);
final saved = await resourceDao.save(null, observation1);

expect(saved.id, Id('obs1'));

expect((saved as Observation).code.text, 'Observation #1');
});

test('Save Observation1 Again', () async {
final observation1 = Observation(
id: Id('obs1'),
code: CodeableConcept(text: 'Observation #1 - Updated'));
final saved = await resourceDao.save(null, observation1);

expect(saved.id, Id('obs1'));

expect((saved as Observation).code.text, 'Observation #1 - Updated');

expect(saved.meta?.versionId, Id('2'));
});

test('Save Observation2', () async {
final observation2 = Observation(
id: Id('obs2'),
code: CodeableConcept(text: 'Observation #2'),
effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
);
final saved = await resourceDao.save(null, observation2);

expect(saved.id, Id('obs2'));

expect((saved as Observation).code.text, 'Observation #2');
});

test('Save Observation3', () async {
final observation3 = Observation(
id: Id('obs3'),
code: CodeableConcept(text: 'Observation #3'),
effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
);
final saved = await resourceDao.save(null, observation3);

expect(saved.id, Id('obs3'));

expect((saved as Observation).code.text, 'Observation #3');
});
});

group('Finding Things:', () {
test('Find 1st Patient', () async {
final search = await resourceDao.find(null,
resourceType: R4ResourceType.Patient, id: id);
final humanName = HumanName(family: 'Atreides', given: ['Duke']);

expect(search.length, 1);

expect((search[0] as Patient).name?[0], humanName);
});

test('Find 3rd Observation', () async {
final search = await resourceDao.find(null,
resourceType: R4ResourceType.Observation, id: Id('obs3'));

expect(search.length, 1);

expect(search[0].id, Id('obs3'));

expect((search[0] as Observation).code.text, 'Observation #3');
});

test('Find All Observations', () async {
final search = await resourceDao.getResourceType(
null,
resourceTypes: [R4ResourceType.Observation],
);

expect(search.length, 3);

final idList = [];
for (final obs in search) {
}

expect(idList.contains('obs1'), true);

expect(idList.contains('obs2'), true);

expect(idList.contains('obs3'), true);
});

test('Find All (non-historical) Resources', () async {
final search = await resourceDao.getAll(null);

expect(search.length, 5);
final patList = search.toList();
final orgList = search.toList();
final obsList = search.toList();
patList.retainWhere(
(resource) => resource.resourceType == R4ResourceType.Patient);
orgList.retainWhere(
(resource) => resource.resourceType == R4ResourceType.Organization);
obsList.retainWhere(
(resource) => resource.resourceType == R4ResourceType.Observation);

expect(patList.length, 1);

expect(orgList.length, 1);

expect(obsList.length, 3);
});
});

group('Deleting Things:', () {
test('Delete 2nd Observation', () async {
await resourceDao.delete(
null, null, R4ResourceType.Observation, Id('obs2'), null, null);

final search = await resourceDao.getResourceType(
null,
resourceTypes: [R4ResourceType.Observation],
);

expect(search.length, 2);

final idList = [];
for (final obs in search) {
}

expect(idList.contains('obs1'), true);

expect(idList.contains('obs2'), false);

expect(idList.contains('obs3'), true);
});

test('Delete All Observations', () async {
await resourceDao.deleteSingleType(null,
resourceType: R4ResourceType.Observation);

final search = await resourceDao.getAll(null);

expect(search.length, 2);

final patList = search.toList();
final orgList = search.toList();
patList.retainWhere(
(resource) => resource.resourceType == R4ResourceType.Patient);
orgList.retainWhere(
(resource) => resource.resourceType == R4ResourceType.Organization);

expect(patList.length, 1);

expect(patList.length, 1);
});

test('Delete All Resources', () async {
await resourceDao.deleteAllResources(null);

final search = await resourceDao.getAll(null);

expect(search.length, 0);
});
});

group('Password - Saving Things:', () {
test('Save Patient', () async {
await resourceDao.updatePw(null, 'newPw');
final humanName = HumanName(family: 'Atreides', given: ['Duke']);
final patient = Patient(id: id, name: [humanName]);
final saved = await resourceDao.save('newPw', patient);

expect(saved.id, id);

expect((saved as Patient).name?[0], humanName);
});

test('Save Organization', () async {
final organization = Organization(id: id, name: 'FhirFli');
final saved = await resourceDao.save('newPw', organization);

expect(saved.id, id);

expect((saved as Organization).name, 'FhirFli');
});

test('Save Observation1', () async {
final observation1 = Observation(
id: Id('obs1'),
code: CodeableConcept(text: 'Observation #1'),
effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
);
final saved = await resourceDao.save('newPw', observation1);

expect(saved.id, Id('obs1'));

expect((saved as Observation).code.text, 'Observation #1');
});

test('Save Observation1 Again', () async {
final observation1 = Observation(
id: Id('obs1'),
code: CodeableConcept(text: 'Observation #1 - Updated'));
final saved = await resourceDao.save('newPw', observation1);

expect(saved.id, Id('obs1'));

expect((saved as Observation).code.text, 'Observation #1 - Updated');

expect(saved.meta?.versionId, Id('2'));
});

test('Save Observation2', () async {
final observation2 = Observation(
id: Id('obs2'),
code: CodeableConcept(text: 'Observation #2'),
effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
);
final saved = await resourceDao.save('newPw', observation2);

expect(saved.id, Id('obs2'));

expect((saved as Observation).code.text, 'Observation #2');
});

test('Save Observation3', () async {
final observation3 = Observation(
id: Id('obs3'),
code: CodeableConcept(text: 'Observation #3'),
effectiveDateTime: FhirDateTime(DateTime(1981, 09, 18)),
);
final saved = await resourceDao.save('newPw', observation3);

expect(saved.id, Id('obs3'));

expect((saved as Observation).code.text, 'Observation #3');
});
});

group('Password - Finding Things:', () {
test('Find 1st Patient', () async {
final search = await resourceDao.find('newPw',
resourceType: R4ResourceType.Patient, id: id);
final humanName = HumanName(family: 'Atreides', given: ['Duke']);

expect(search.length, 1);

expect((search[0] as Patient).name?[0], humanName);
});

test('Find 3rd Observation', () async {
final search = await resourceDao.find('newPw',
resourceType: R4ResourceType.Observation, id: Id('obs3'));

expect(search.length, 1);

expect(search[0].id, Id('obs3'));

expect((search[0] as Observation).code.text, 'Observation #3');
});

test('Find All Observations', () async {
final search = await resourceDao.getResourceType(
'newPw',
resourceTypes: [R4ResourceType.Observation],
);

expect(search.length, 3);

final idList = [];
for (final obs in search) {
}

expect(idList.contains('obs1'), true);

expect(idList.contains('obs2'), true);

expect(idList.contains('obs3'), true);
});

test('Find All (non-historical) Resources', () async {
final search = await resourceDao.getAll('newPw');

expect(search.length, 5);
final patList = search.toList();
final orgList = search.toList();
final obsList = search.toList();
patList.retainWhere(
(resource) => resource.resourceType == R4ResourceType.Patient);
orgList.retainWhere(
(resource) => resource.resourceType == R4ResourceType.Organization);
obsList.retainWhere(
(resource) => resource.resourceType == R4ResourceType.Observation);

expect(patList.length, 1);

expect(orgList.length, 1);

expect(obsList.length, 3);
});
});

group('Password - Deleting Things:', () {
test('Delete 2nd Observation', () async {
await resourceDao.delete(
'newPw', null, R4ResourceType.Observation, Id('obs2'), null, null);

final search = await resourceDao.getResourceType(
'newPw',
resourceTypes: [R4ResourceType.Observation],
);

expect(search.length, 2);

final idList = [];
for (final obs in search) {
}

expect(idList.contains('obs1'), true);

expect(idList.contains('obs2'), false);

expect(idList.contains('obs3'), true);
});

test('Delete All Observations', () async {
await resourceDao.deleteSingleType('newPw',
resourceType: R4ResourceType.Observation);

final search = await resourceDao.getAll('newPw');

expect(search.length, 2);

final patList = search.toList();
final orgList = search.toList();
patList.retainWhere(
(resource) => resource.resourceType == R4ResourceType.Patient);
orgList.retainWhere(
(resource) => resource.resourceType == R4ResourceType.Organization);

expect(patList.length, 1);

expect(patList.length, 1);
});

test('Delete All Resources', () async {
await resourceDao.deleteAllResources('newPw');

final search = await resourceDao.getAll('newPw');

expect(search.length, 0);

await resourceDao.updatePw('newPw', null);
});
});
} ``````

Author: MayJuun

1624934525

## Python I: Data Types and Operators, variable assignment, and print()

### Learn the Python basics so that you can use it for your data science projects.

This blog is part of a series of tutorials called Data in Day. Follow these tutorials to create your first end-to-end data science project in just one day. This is a fun easy project that will teach you the basics of setting up your computer for a data science project and introduce you to some of the most popular tools available. It is a great way to get acquainted with the data science workflow.

## I. About Python 🐍

Created by Dutch programmer Guido van Rossum at Centrum Wiskunde & Informatica, Python made its debut in 1991. Over thirty years it has gained popularity earned a reputation of being the “Swiss army knife of programming languages.” Here are a few reasons why:

In emerging fields like data science, artificial intelligence, and machine learning, a robust community, plenty of packages, paradigm flexibility, and syntactical simplicity, allow beginners and professionals to focus on insights and innovation.

#python3 #variables-in-python #data-types-in-python #operators-in-python #python #python i: data types and operators, variable assignment, and print()