# -*- coding: utf-8 -*-


res = {
    "data": {
        "paper_meta": {
            "author_list": [
                {
                    "name": "Dr. Gareth Barnes",
                    "org": ", Aston University, Birmingham, UK"
                },
                {
                    "name": "Dr. Arjan Hillebrand",
                    "org": ", VU University Medical Center, Department of Clinical Neurophysiology, Amsterdam, The Netherlands"
                },
                {
                    "name": "Dr. Masayuki Hirata",
                    "org": ", Department of Neurosurgery, Osaka University Medical School, Suita, Osaka, Japan"
                }
            ],
            "issn": [
                {
                    "electronic_issn": "1941-6016"
                }
            ],
            "issued_time": "2010/7/12",
            "journal": [
                {
                    "firstpage": "3172",
                    "issue": "7",
                    "lastpage": "",
                    "name": "Scholarpedia",
                    "volume": "5"
                }
            ],
            "references": [
                {
                    "links": "",
                    "title": "Baayen JC, de Jongh A, Stam CJ, de Munck JC, Jonkman JJ, Trenité DG, Berendse HW, van Walsum AM, Heimans JJ, Puligheddu M, Castelijns JA, Vandertop WP (2003) Localization of slow wave activity in patients with tumor-associated epilepsy. Brain Topogr. 16(2):85-93."
                },
                {
                    "links": "",
                    "title": "Baillet, S Garnero L (1997) A Bayesian Approach to Introducing Anatomo-Functional Priors in the EEG/MEG Inverse Problem. IEEE Trans. Biomed. Eng. 44:374-385."
                },
                {
                    "links": "",
                    "title": "Barnes GR, Furlong PL, Singh KD, Hillebrand A (2006) A verifiable solution to the MEG inverse problem. Neuroimage 31(2):623-626."
                },
                {
                    "links": "",
                    "title": "Bartolomei F, Bosma I, Klein M, Baayen JC, Reijneveld JC, Postma TJ, Heimans JJ, van Dijk BW, de Munck JC, de Jongh A, Cover KS, Stam CJ (2006) Disturbed functional connectivity in brain tumour patients: evaluation by graph analysis of synchronization matrices. Clin Neurophysiol. 117(9):2039-2049."
                },
                {
                    "links": "",
                    "title": "Baumgartner C, Doppelbauer A, Sutherling WW, Zeitlhofer J, Lindinger G, Lind C, Deecke L (1991) Human somatosensory cortical finger representation as studied by combined neuromagnetic and neuroelectric measurements. Neurosci Lett. 134(1):103-108."
                },
                {
                    "links": "",
                    "title": "Bosma I, Stam CJ, Douw L, Bartolomei F, Heimans JJ, van Dijk BW, Postma TJ, Klein M, Reijneveld JC (2008) The influence of low-grade glioma on resting state oscillatory brain activity: a magnetoencephalography study. J Neurooncol. 88(1):77-85."
                },
                {
                    "links": "",
                    "title": "Brookes MJ, Zumer JM, Stevenson CM, Hale JR, Barnes GR, Vrba J, Morris PG (2010) Investigating spatial specificity and data averaging in MEG. Neuroimage 49(1):525-38."
                },
                {
                    "links": "",
                    "title": "Clarke J (1994) SQUIDs. Scientific American 271(2):46-53."
                },
                {
                    "links": "",
                    "title": "Cohen D (1968) Magnetoencephalography: evidence of magnetic fields produced by alpha-rhythm currents. Science 161:784–786."
                },
                {
                    "links": "",
                    "title": "Cohen D, Schläpfer U, Ahlfors S, Hämäläinen S, Halgren E (2002) New Six-Layer Magnetically-Shielded Room for MEG. Proceedings of Biomag 2002.[2]"
                },
                {
                    "links": "",
                    "title": "Cornwell BR, Carver FW, Coppola R, Johnson L, Alvarez R, Grillon C (2008) Evoked amygdala responses to negative faces revealed by adaptive MEG beamformers. Brain Res. 1244:103-112."
                },
                {
                    "links": "",
                    "title": "Fisher AE, Furlong PL, Seri S, Adjamian P, Witton C, Baldeweg T, Phillips S, Walsh R, Houghton JM, Thai NJ (2008) Interhemispheric differences of spectral power in expressive language: a MEG study with clinical applications. Int J Psychophysiol. 68(2):111-22."
                },
                {
                    "links": "",
                    "title": "Flemming L, Wang Y, Caprihan A, Eiselt M, Haueisen J, Okada Y (2005) Evaluation of the distortion of EEG signals caused by a hole in the skull mimicking the fontanel in the skull of human neonates. Clin Neurophysiol. 116(5):1141-52."
                },
                {
                    "links": "",
                    "title": "Ganslandt O, Ulbricht D, Kober H, Vieth J, Strauss C, Fahlbusch R (1996) SEF-MEG localization of somatosensory cortex as a method for presurgical assessment of functional brain area. Electroencephalography and Clinical Neurophysiology. Supplement 1996; 46:209-13."
                },
                {
                    "links": "",
                    "title": "Hillebrand A, Barnes GR (2002) A quantitative assessment of the sensitivity of whole-head MEG to activity in the adult human cortex. Neuroimage 16(3 Pt1):638-50."
                },
                {
                    "links": "",
                    "title": "Hillebrand, A, Singh KD, Holliday IE, Furlong PL, Barnes GR (2005) A new approach to neuroimaging with magnetoencephalography. Hum. Brain Mapp. 25:199-211."
                },
                {
                    "links": "",
                    "title": "Hirata M, Kato A, Taniguchi M, Saitoh Y, Ninomiya H, Ihara A, et al. (2004) Determination of language dominance with synthetic aperture magnetometry: comparison with the Wada test. Neuroimage 23:46-53."
                },
                {
                    "links": "",
                    "title": "Huang MX, Mosher JC, Leahy RM(1999) A sensor-weighted overlapping-sphere head model and exhaustive head model comparison for MEG. Phys Med Biol. 44(2):423-40."
                },
                {
                    "links": "",
                    "title": "Jerbi K, Mosher JC, Baillet S, Leahy RM (2002) On MEG forward modelling using multipolar expansions. Phys Med Biol. 47(4):523-55."
                },
                {
                    "links": "",
                    "title": "Kilner JM, Kiebel SJ, Friston KJ (2005) Applications of random field theory to electrophysiology. Neuroscience Letters 374:174–178."
                },
                {
                    "links": "",
                    "title": "Knowlton R, Shih J (2004) Magnetoencephalography in epilepsy. Epilepsia 45 Suppl 4:61-71."
                },
                {
                    "links": "",
                    "title": "Lewine JD, Davis JT, Bigler ED, Thoma R, Hill D, Funke M, Sloan JH, Hall S, Orrison WW (2007) Objective documentation of traumatic brain injury subsequent to mild head trauma: multimodal brain imaging with MEG, SPECT, and MRI. J Head Trauma Rehabil. 22(3):141-155."
                },
                {
                    "links": "",
                    "title": "Mattout, J, Phillips C, Penny WD, Rugg MD, Friston, KJ (2006) MEG source localization under multiple constraints: an extended Bayesian framework. Neuroimage 30:753-767."
                },
                {
                    "links": "",
                    "title": "Mosher JC, Spencer ME, Leahy RM, Lewis PS (1993) Error bounds for EEG and MEG dipole source localization. Electroencephalogr Clin Neurophysiol. 86(5):303-21."
                },
                {
                    "links": "",
                    "title": "Murakami S, Okada Y (2006) Contributions of principal neocortical neurons to magnetoencephalography and electroencephalography signals. J. Physiol. 575:925-936."
                },
                {
                    "links": "",
                    "title": "Nagarajan S, Kirsch H, Lin P, Findlay A, Honma S, Berger MS (2008) Preoperative localization of hand motor cortex by adaptive spatial filtering of magnetoencephalography data. J Neurosurg. 109(2):228-237."
                },
                {
                    "links": "",
                    "title": "Nurminen J, Taulu S, Okada Y (2008) Effects of sensor calibration, balancing and parametrization on the signal space separation method. Phys Med Biol. 53(7):1975-87."
                },
                {
                    "links": "",
                    "title": "Oshino S, Kato A, Wakayama A, Taniguchi M, Hirata M, Yoshimine T (2007) Magnetoencephalographic analysis of cortical oscillatory activity in patients with brain tumors: Synthetic aperture magnetometry (SAM) functional imaging of delta band activity. Neuroimage 34(3):957-964."
                },
                {
                    "links": "",
                    "title": "Pang EW, Drake JM, Otsubo H, Martineau A, Strantzas S, Cheyne D, Gaetz W (2008) Intraoperative confirmation of hand motor area identified preoperatively by magnetoencephalography. Pediatr Neurosurg. 44(4):313-317"
                },
                {
                    "links": "",
                    "title": "Pantazis D, Nichols TE, Baillet S, Leahy RM (2005) A comparison of random field theory and permutation methods for the statistical analysis of MEG data. Neuroimage 25(2):383-94."
                },
                {
                    "links": "",
                    "title": "Pasqual-Marqui, RD, Michel CM, Lehmann D (1994) Low Resolution Electromagnetic Tomography: A New Method for Localizing Electrical Activity in the Brain. Int. J Psychophysiol. 18:49-65."
                },
                {
                    "links": "",
                    "title": "Riggs L, Moses SN, Bardouille T, Herdman AT, Ross B, Ryan JD (2009) A complementary analytic approach to examining medial temporal lobe sources using magnetoencephalography. Neuroimage 45(2):627-42."
                },
                {
                    "links": "",
                    "title": "Sarvas J (1987) Basic mathematical and electromagnetic concepts of the biomagnetic inverse problem. Phys Med Biol. 32(1):11-22."
                },
                {
                    "links": "",
                    "title": "Sato MA, Yoshioka T, Kajihara S, Toyama K, Goda N, Doya K, Kawato M (2004) Hierarchical Bayesian estimation for MEG inverse problem. Neuroimage 23(3):806-826."
                },
                {
                    "links": "",
                    "title": "Singh KD, Barnes GR, Hillebrand A (2003) Group imaging of task-related changes in cortical synchronisation using nonparametric permutation testing. Neuroimage 19(4):1589-1601."
                },
                {
                    "links": "",
                    "title": "Stam CJ, de Haan W, Daffertshofer A, Jones BF, Manshanden I, van Cappellen van Walsum AM, Montez T, Verbunt JP, de Munck JC, van Dijk BW, Berendse HW, Scheltens P (2009) Graph theoretical analysis of magnetoencephalographic functional connectivity in Alzheimer's disease. Brain 132(Pt1):213-224."
                },
                {
                    "links": "",
                    "title": "Stoffers D, Bosboom JL, Deijen JB, Wolters ECh, Stam CJ, Berendse HW (2008) Increased cortico-cortical functional connectivity in early-stage Parkinson's disease: an MEG study. Neuroimage 41(2):212-222."
                },
                {
                    "links": "",
                    "title": "Stufflebeam SM, Tanaka N, Ahlfors SP (2009) Clinical applications of magnetoencephalography. Hum Brain Mapp. 30(6):1813-1823."
                },
                {
                    "links": "",
                    "title": "Supek S, Aine CJ, Ranken D, Best E, Flynn ER, Wood CC (1999) Single vs. paired visual stimulation: superposition of early neuromagnetic responses and retinotopy in extrastriate cortex in humans. Brain Res. 830(1):43-55."
                },
                {
                    "links": "",
                    "title": "Supek S, Aine CJ (1993) Simulation studies of multiple dipole neuromagnetic source localization: model order and limits of source resolution. IEEE Trans Biomed Eng. 40(6):529-540"
                },
                {
                    "links": "",
                    "title": "Tanaka N, Cole AJ, von Pechmann D, Wakeman DG, Hämäläinen MS, Liu H, Madsen JR, Bourgeois BF, Stufflebeam SM (2009) Dynamic statistical parametric mapping for analyzing ictal magnetoencephalographic spikes in patients with intractable frontal lobe epilepsy. Epilepsy Res. 85(2-3):279-286."
                },
                {
                    "links": "",
                    "title": "Taulu S and Kajola M (2005) Presentation of electromagnetic multichannel data: the signal space separation method. J. Appl. Phys. 97(12):124905."
                },
                {
                    "links": "",
                    "title": "Timmermann L, Gross J, Dirks M, Volkmann J, Freund HJ, Schnitzler A (2003) The cerebral oscillatory network of parkinsonian resting tremor. Brain 126(Pt 1):199-212."
                },
                {
                    "links": "",
                    "title": "Vrba J, Taylor B, Cheung T, Fife AA, Haid G, Kubik PR, Lee S, McCubbin J, Burbank MD (1995) noise cancellation by a whole-Cortex SQUID MEG System. IEEE Transactions on Applied Superconductivity 5(2 Pt3):2118-2123."
                }
            ],
            "title": "Magnetoencephalogram"
        }
    }
}

def processor(res):
  paper_meta = res['data']['paper_meta']
  # case 特殊处理
  # journal 中的 firstpage 和 lastpage 处理为 page
  for index, journal in enumerate(paper_meta['journal']):
      # lastpage 不为空的情况下处理为 firstpage - lastpage 形式
      if journal['lastpage']:
          page = journal['firstpage'] + '-' + journal['lastpage']
      # 否则 page 为 firstpage
      else:
          page = journal['firstpage']
      # 更新原值
      paper_meta['journal'][index].update(page=page)
    

  # 去除 journal 中的空白字段
  # 去除 journal 中的空白字段
  new_journal_list = []
  for journal in paper_meta['journal']:
      # 初始化单个 journal 字典
      new_journal_dict = {}
      for journal_key in journal:
          # 保留有效字段(# 额外处理 firstpage 和 lastpage)
          if journal[journal_key] and journal_key != 'firstpage' and journal_key != 'lastpage':
              print journal_key
              new_journal_dict[journal_key] = journal[journal_key]
          # 空白字段跳过
          else:
              continue
      # 更新 new_journal_list
      new_journal_list.append(new_journal_dict)
  # 覆盖原值
  res['data']['paper_meta']['journal'] = new_journal_list
  return res
  
processor(res) 

Python Online Compiler

Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2. OneCompiler also has reference programs, where you can look for the sample code and start coding.

Taking inputs (stdin)

OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.

import sys
name = sys.stdin.readline()
print("Hello "+ name)

About Python

Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.

Tutorial & Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition IF-ELSE is used.

if conditional-expression
    #code
elif conditional-expression
    #code
else:
    #code

Note:

Indentation is very important in Python, make sure the indentation is followed correctly

2. For:

For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.

Example:

mylist=("Iphone","Pixel","Samsung")
for i in mylist:
    print(i)

3. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while condition  
    #code 

Collections

There are four types of collections in Python.

1. List:

List is a collection which is ordered and can be changed. Lists are specified in square brackets.

Example:

mylist=["iPhone","Pixel","Samsung"]
print(mylist)

2. Tuple:

Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.

Example:

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)

Below throws an error if you assign another value to tuple again.

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)

3. Set:

Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.

Example:

myset{"iPhone","Pixel","Samsung"}
print{myset}

4. Dictionary:

Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.

Example:

mydict = {
    "brand" :"iPhone",
    "model": "iPhone 11"
}
print(mydict)