Java Python比較辞書


縦分割はありませんか?
https://wikidocs.net/book/31
JAvaの定式この本もいいので、時間があれば探してみましょう.
3.資料型
1.数値oct(19) || int a = 023 hex(12) || int a =0xC2. BooleanTrue || true False || false 0(False),1(True),''(False),"abz"(True) || 없음4.文字列a[index] || a.charAt(indxe) a.index(b) || a.indexOf(b) b in a || a.contains(b) a = a.replace(b,c) || a = a.replaceAll(b,c) a[b:c] || a.substring(a,b+1) a.upper() || a.toUpperCase() a.split(b) || a.split(b)7.明細書
# python 리스트 생성
a = []
// java 리스트 생성
import java.util.ArrayList;
ArrayList a = new ArrayList();
lst.append(a) // lst.add(a) lst[idx] // lst.get(idx) len(lst) // lst.size() b in lst // lst.contains(b) del lst[idx] // lst.remove(idx) "sep".join(lst)// String.join(sep,lst) lst[a:b] // lst.subList(a,b) lst[idx] = b // lst.set(idx,b)
# python 리스트 정렬
a= [2,3,1]
a.sort()
a.sort(reverse = True)
// java 리스트 정렬

import java.util.ArrayList;
import java.util.Comparator;
ArrayList a = new ArrayList();
a.add(2);
a.add(3);
a.add(1);
a.sort(Comparator.naturalOrder());
a.sort(Comparator.reverseOrder());
9.地図dict // hashmap dct = {} // HashMap<String, String> map = new HashMap<>(); dct[key] = value // map.put(key,value) dct[key] // map.get(key) if key in dct.keys() // map.containsKey(key) len(dct) // map.size() del dct[key] // map.remove(key) list(dct.keys()) // List<String> keyList = new ArrayList<>(map.keySet()); // hmap.keySet(); dict.values()//entrySet();(不確定)
10.集合
4.制御文
#python
for i in range(N):
    print(i)

arr = [a,b,c]
for s in arr:
    print(s)
// java
for(int i =0;i<N;i++){
    System.out.println(i);
}

String[] arr = {"a","b","c"};
for (String s : arr){
    System.out.println(s);
}
6.I/O
# python
N = int(input())
# G C G G C를 [G,C,G,G,C]로
lst = list(input().split(' '))
# 파일로 입력
f = open("C:/doit/새파일.txt", 'r')
while True:
    line = f.readline()
    if not line: 
        break
    print(line)
f.close()
# 데이터가 없을때까지 받기
// java
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
// G C G G C를 [G,C,G,G,C]로
String[] lst;
lst = sc.nextLine().split(" ");
// 파일로 입력
System.setIn(new FileInputStream(파일));
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
    line = sc.nextLine();
    System.out.println(line);
}
その他
GCD
#파이썬
def GCD(x,y):
    while y:
        x,y = y,x%y
    return y
//자바
    public int GCD(int n, int m){ 
        int tmp;        
        while (m != 0){
            tmp = n;
            n = m;
            m = tmp%m;
        }
        return n;
    }
初期化
#파이썬
def func(a = 0){
}
//java
public class func{
    int a;
    
    func(int a){
    	super();
        this.a = a;
    }
    func(){
	this(0);
    }

}
dict vs hashmap
# 파이썬
dct = {}
dct[1] = 2
dct[1] +=1
print(dct[1])
// java
		HashMap<Integer, Integer> map = new HashMap<>();
		map.put(1, 2);
		System.out.println(map.get(1));
		map.put(1, map.get(1)+1);
		System.out.println(map.get(1));