16,395 questions
21,880 answers
573 users
lst = ["python", "php" , "java" , "c#"] dic = {i : lst[i] for i in range(0, len(lst))} print(dic) ''' run: {0: 'python', 1: 'php', 2: 'java', 3: 'c#'} '''
lst = ["python", "php" , "java" , "c#"] dic = {lst[i] : i for i in range(0, len(lst))} print(dic) ''' run: {'python': 0, 'php': 1, 'java': 2, 'c#': 3} '''
lst = [34, 'python', 60, 'java', 17, 'c++'] dic = {lst[i]: lst[i + 1] for i in range(0, len(lst), 2)} print(dic) ''' run: {34: 'python', 60: 'java', 17: 'c++'} '''