Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python 3.8.5 (default, Jan 27 2021, 15:41:15)
- [GCC 9.3.0] on linux
- Type "help", "copyright", "credits" or "license()" for more information.
- >>> slownik = { "klucz" : "wartość" }
- >>> slownik
- {'klucz': 'wartość'}
- >>> slownik["klucz"]
- 'wartość'
- >>> slownik["klucz_1"] = "Adam"
- >>> slownik
- {'klucz': 'wartość', 'klucz_1': 'Adam'}
- >>> slownik["klucz"] = "Python"
- >>> slownik
- {'klucz': 'Python', 'klucz_1': 'Adam'}
- >>> slownik_2 = { 1: "Adam", 45: "Jurkiewicz", 4: "Linux" }
- >>> slownik_2[1]
- 'Adam'
- >>> slownik_2[4]
- 'Linux'
- >>> slownik_2[45]
- 'Jurkiewicz'
- >>> slownik[len(slownik_2[1])]
- Traceback (most recent call last):
- File "<pyshell#12>", line 1, in <module>
- slownik[len(slownik_2[1])]
- KeyError: 4
- >>> slownik_2[len(slownik_2[1])]
- 'Linux'
- >>> slownik_3 = { 1 : 45.45, 2: { "A" : "Adam" } }
- >>> slownik_3
- {1: 45.45, 2: {'A': 'Adam'}}
- >>> slownik_3[1]
- 45.45
- >>> slownik_3[2]
- {'A': 'Adam'}
- >>> slownik_3[2]["A"]
- 'Adam'
- >>> slownik_3[1]["A"]
- Traceback (most recent call last):
- File "<pyshell#19>", line 1, in <module>
- slownik_3[1]["A"]
- TypeError: 'float' object is not subscriptable
- >>> places = {
- "Anglia_1": {
- "background_file": "rooms-england-bletchley-park-01.jpg",
- "attachment_file": "rooms-england-bletchley-park-01.png",
- },
- "Anglia_2": {
- "background_file": "rooms-england-bletchley-park-02.jpg",
- "attachment_file": "rooms-england-bletchley-park-02.png",
- },
- "Anglia_3": {
- "background_file": "rooms-england-bletchley-park-03.jpg",
- "attachment_file": "rooms-england-bletchley-park-03.png",
- },
- "Francja_1": {
- "background_file": "rooms-france-paris-01.jpg",
- "attachment_file": "rooms-france-paris-01.png",
- },
- "Francja_2": {
- "background_file": "rooms-france-paris-02.jpg",
- "attachment_file": "rooms-france-paris-02.png",
- },
- "Francja_3": {
- "background_file": "rooms-france-paris-03.jpg",
- "attachment_file": "rooms-france-paris-03.png",
- },
- "Niemcy_1": {
- "background_file": "rooms-german-uboot-01.jpg",
- "attachment_file": "rooms-german-uboot-01.png",
- },
- "Niemcy_2": {
- "background_file": "rooms-german-uboot-02.jpg",
- "attachment_file": "rooms-german-uboot-02.png",
- },
- "Lwow_1": {
- "background_file": "rooms-poland-lwow-sknilow-01.jpg",
- "attachment_file": "rooms-poland-lwow-sknilow-01.png",
- },
- "Lwow_2": {
- "background_file": "rooms-poland-lwow-sknilow-02.jpg",
- "attachment_file": "rooms-poland-lwow-sknilow-02.png",
- },
- "Polska_1": {
- "background_file": "rooms-poland-warsaw-cipher-bureau-01.jpg",
- "attachment_file": "rooms-poland-warsaw-cipher-bureau-01.png",
- },
- "Polska_2": {
- "background_file": "rooms-poland-warsaw-cipher-bureau-02.jpg",
- "attachment_file": "rooms-poland-warsaw-cipher-bureau-02.png",
- },
- "Polska_3": {
- "background_file": "rooms-poland-warsaw-cipher-bureau-03.jpg",
- "attachment_file": "rooms-poland-warsaw-cipher-bureau-03.png",
- },
- "Polska_4": {
- "background_file": "rooms-poland-warsaw-cipher-bureau-04.jpg",
- "attachment_file": "rooms-poland-warsaw-cipher-bureau-04.png",
- },
- }
- >>> places
- {'Anglia_1': {'background_file': 'rooms-england-bletchley-park-01.jpg', 'attachment_file': 'rooms-england-bletchley-park-01.png'}, 'Anglia_2': {'background_file': 'rooms-england-bletchley-park-02.jpg', 'attachment_file': 'rooms-england-bletchley-park-02.png'}, 'Anglia_3': {'background_file': 'rooms-england-bletchley-park-03.jpg', 'attachment_file': 'rooms-england-bletchley-park-03.png'}, 'Francja_1': {'background_file': 'rooms-france-paris-01.jpg', 'attachment_file': 'rooms-france-paris-01.png'}, 'Francja_2': {'background_file': 'rooms-france-paris-02.jpg', 'attachment_file': 'rooms-france-paris-02.png'}, 'Francja_3': {'background_file': 'rooms-france-paris-03.jpg', 'attachment_file': 'rooms-france-paris-03.png'}, 'Niemcy_1': {'background_file': 'rooms-german-uboot-01.jpg', 'attachment_file': 'rooms-german-uboot-01.png'}, 'Niemcy_2': {'background_file': 'rooms-german-uboot-02.jpg', 'attachment_file': 'rooms-german-uboot-02.png'}, 'Lwow_1': {'background_file': 'rooms-poland-lwow-sknilow-01.jpg', 'attachment_file': 'rooms-poland-lwow-sknilow-01.png'}, 'Lwow_2': {'background_file': 'rooms-poland-lwow-sknilow-02.jpg', 'attachment_file': 'rooms-poland-lwow-sknilow-02.png'}, 'Polska_1': {'background_file': 'rooms-poland-warsaw-cipher-bureau-01.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-01.png'}, 'Polska_2': {'background_file': 'rooms-poland-warsaw-cipher-bureau-02.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-02.png'}, 'Polska_3': {'background_file': 'rooms-poland-warsaw-cipher-bureau-03.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-03.png'}, 'Polska_4': {'background_file': 'rooms-poland-warsaw-cipher-bureau-04.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-04.png'}}
- >>> for sc in places:
- print(sc)
- Anglia_1
- Anglia_2
- Anglia_3
- Francja_1
- Francja_2
- Francja_3
- Niemcy_1
- Niemcy_2
- Lwow_1
- Lwow_2
- Polska_1
- Polska_2
- Polska_3
- Polska_4
- >>> for sc in places:
- print(sc)
- print(plases[sc])
- Anglia_1
- Traceback (most recent call last):
- File "<pyshell#27>", line 3, in <module>
- print(plases[sc])
- NameError: name 'plases' is not defined
- >>> for sc in places:
- print(sc)
- print(places[sc])
- Anglia_1
- {'background_file': 'rooms-england-bletchley-park-01.jpg', 'attachment_file': 'rooms-england-bletchley-park-01.png'}
- Anglia_2
- {'background_file': 'rooms-england-bletchley-park-02.jpg', 'attachment_file': 'rooms-england-bletchley-park-02.png'}
- Anglia_3
- {'background_file': 'rooms-england-bletchley-park-03.jpg', 'attachment_file': 'rooms-england-bletchley-park-03.png'}
- Francja_1
- {'background_file': 'rooms-france-paris-01.jpg', 'attachment_file': 'rooms-france-paris-01.png'}
- Francja_2
- {'background_file': 'rooms-france-paris-02.jpg', 'attachment_file': 'rooms-france-paris-02.png'}
- Francja_3
- {'background_file': 'rooms-france-paris-03.jpg', 'attachment_file': 'rooms-france-paris-03.png'}
- Niemcy_1
- {'background_file': 'rooms-german-uboot-01.jpg', 'attachment_file': 'rooms-german-uboot-01.png'}
- Niemcy_2
- {'background_file': 'rooms-german-uboot-02.jpg', 'attachment_file': 'rooms-german-uboot-02.png'}
- Lwow_1
- {'background_file': 'rooms-poland-lwow-sknilow-01.jpg', 'attachment_file': 'rooms-poland-lwow-sknilow-01.png'}
- Lwow_2
- {'background_file': 'rooms-poland-lwow-sknilow-02.jpg', 'attachment_file': 'rooms-poland-lwow-sknilow-02.png'}
- Polska_1
- {'background_file': 'rooms-poland-warsaw-cipher-bureau-01.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-01.png'}
- Polska_2
- {'background_file': 'rooms-poland-warsaw-cipher-bureau-02.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-02.png'}
- Polska_3
- {'background_file': 'rooms-poland-warsaw-cipher-bureau-03.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-03.png'}
- Polska_4
- {'background_file': 'rooms-poland-warsaw-cipher-bureau-04.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-04.png'}
- >>> dir(places)
- ['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
- >>> places.keys()
- dict_keys(['Anglia_1', 'Anglia_2', 'Anglia_3', 'Francja_1', 'Francja_2', 'Francja_3', 'Niemcy_1', 'Niemcy_2', 'Lwow_1', 'Lwow_2', 'Polska_1', 'Polska_2', 'Polska_3', 'Polska_4'])
- >>> from random import randint, choice
- >>> help(choice())
- Traceback (most recent call last):
- File "<pyshell#33>", line 1, in <module>
- help(choice())
- TypeError: choice() missing 1 required positional argument: 'seq'
- >>> help(choice)
- Help on method choice in module random:
- choice(seq) method of random.Random instance
- Choose a random element from a non-empty sequence.
- >>> choice(places.keys())
- Traceback (most recent call last):
- File "<pyshell#35>", line 1, in <module>
- choice(places.keys())
- File "/usr/lib/python3.8/random.py", line 291, in choice
- return seq[i]
- TypeError: 'dict_keys' object is not subscriptable
- >>> choice(dict(places.keys()))
- Traceback (most recent call last):
- File "<pyshell#36>", line 1, in <module>
- choice(dict(places.keys()))
- ValueError: dictionary update sequence element #0 has length 8; 2 is required
- >>> choice(list(places.keys()))
- 'Anglia_3'
- >>> choice(list(places.keys()))
- 'Francja_1'
- >>> choice(list(places.keys()))
- 'Lwow_2'
- >>> choice(list(places.keys()))
- 'Niemcy_1'
- >>> choice(list(places.keys()))
- 'Polska_2'
- >>> choice(list(places.keys()))
- 'Anglia_1'
- >>> choice(list(places.keys()))
- 'Polska_3'
- >>> choice(list(places.keys()))
- 'Polska_4'
- >>> choice(list(places.keys()))
- 'Anglia_1'
- >>> choice(list(places.keys()))
- 'Francja_3'
- >>> choice(list(places.keys()))
- 'Lwow_1'
- >>> choice(list(places.keys()))
- 'Polska_2'
- >>> choice(list(places.keys()))
- 'Polska_2'
- >>> choice(list(places.keys()))
- 'Francja_3'
- >>> place = "Polska_2"
- >>> places[place]["background_file"]
- 'rooms-poland-warsaw-cipher-bureau-02.jpg'
- >>> import json
- >>> dir(json)
- ['JSONDecodeError', 'JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_default_decoder', '_default_encoder', 'codecs', 'decoder', 'detect_encoding', 'dump', 'dumps', 'encoder', 'load', 'loads', 'scanner']
- >>> places
- {'Anglia_1': {'background_file': 'rooms-england-bletchley-park-01.jpg', 'attachment_file': 'rooms-england-bletchley-park-01.png'}, 'Anglia_2': {'background_file': 'rooms-england-bletchley-park-02.jpg', 'attachment_file': 'rooms-england-bletchley-park-02.png'}, 'Anglia_3': {'background_file': 'rooms-england-bletchley-park-03.jpg', 'attachment_file': 'rooms-england-bletchley-park-03.png'}, 'Francja_1': {'background_file': 'rooms-france-paris-01.jpg', 'attachment_file': 'rooms-france-paris-01.png'}, 'Francja_2': {'background_file': 'rooms-france-paris-02.jpg', 'attachment_file': 'rooms-france-paris-02.png'}, 'Francja_3': {'background_file': 'rooms-france-paris-03.jpg', 'attachment_file': 'rooms-france-paris-03.png'}, 'Niemcy_1': {'background_file': 'rooms-german-uboot-01.jpg', 'attachment_file': 'rooms-german-uboot-01.png'}, 'Niemcy_2': {'background_file': 'rooms-german-uboot-02.jpg', 'attachment_file': 'rooms-german-uboot-02.png'}, 'Lwow_1': {'background_file': 'rooms-poland-lwow-sknilow-01.jpg', 'attachment_file': 'rooms-poland-lwow-sknilow-01.png'}, 'Lwow_2': {'background_file': 'rooms-poland-lwow-sknilow-02.jpg', 'attachment_file': 'rooms-poland-lwow-sknilow-02.png'}, 'Polska_1': {'background_file': 'rooms-poland-warsaw-cipher-bureau-01.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-01.png'}, 'Polska_2': {'background_file': 'rooms-poland-warsaw-cipher-bureau-02.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-02.png'}, 'Polska_3': {'background_file': 'rooms-poland-warsaw-cipher-bureau-03.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-03.png'}, 'Polska_4': {'background_file': 'rooms-poland-warsaw-cipher-bureau-04.jpg', 'attachment_file': 'rooms-poland-warsaw-cipher-bureau-04.png'}}
- >>> json.dumps(places)
- '{"Anglia_1": {"background_file": "rooms-england-bletchley-park-01.jpg", "attachment_file": "rooms-england-bletchley-park-01.png"}, "Anglia_2": {"background_file": "rooms-england-bletchley-park-02.jpg", "attachment_file": "rooms-england-bletchley-park-02.png"}, "Anglia_3": {"background_file": "rooms-england-bletchley-park-03.jpg", "attachment_file": "rooms-england-bletchley-park-03.png"}, "Francja_1": {"background_file": "rooms-france-paris-01.jpg", "attachment_file": "rooms-france-paris-01.png"}, "Francja_2": {"background_file": "rooms-france-paris-02.jpg", "attachment_file": "rooms-france-paris-02.png"}, "Francja_3": {"background_file": "rooms-france-paris-03.jpg", "attachment_file": "rooms-france-paris-03.png"}, "Niemcy_1": {"background_file": "rooms-german-uboot-01.jpg", "attachment_file": "rooms-german-uboot-01.png"}, "Niemcy_2": {"background_file": "rooms-german-uboot-02.jpg", "attachment_file": "rooms-german-uboot-02.png"}, "Lwow_1": {"background_file": "rooms-poland-lwow-sknilow-01.jpg", "attachment_file": "rooms-poland-lwow-sknilow-01.png"}, "Lwow_2": {"background_file": "rooms-poland-lwow-sknilow-02.jpg", "attachment_file": "rooms-poland-lwow-sknilow-02.png"}, "Polska_1": {"background_file": "rooms-poland-warsaw-cipher-bureau-01.jpg", "attachment_file": "rooms-poland-warsaw-cipher-bureau-01.png"}, "Polska_2": {"background_file": "rooms-poland-warsaw-cipher-bureau-02.jpg", "attachment_file": "rooms-poland-warsaw-cipher-bureau-02.png"}, "Polska_3": {"background_file": "rooms-poland-warsaw-cipher-bureau-03.jpg", "attachment_file": "rooms-poland-warsaw-cipher-bureau-03.png"}, "Polska_4": {"background_file": "rooms-poland-warsaw-cipher-bureau-04.jpg", "attachment_file": "rooms-poland-warsaw-cipher-bureau-04.png"}}'
- >>> json.dumps(plases, indent=3)
- Traceback (most recent call last):
- File "<pyshell#57>", line 1, in <module>
- json.dumps(plases, indent=3)
- NameError: name 'plases' is not defined
- >>> json.dumps(places, indent=3)
- '{\n "Anglia_1": {\n "background_file": "rooms-england-bletchley-park-01.jpg",\n "attachment_file": "rooms-england-bletchley-park-01.png"\n },\n "Anglia_2": {\n "background_file": "rooms-england-bletchley-park-02.jpg",\n "attachment_file": "rooms-england-bletchley-park-02.png"\n },\n "Anglia_3": {\n "background_file": "rooms-england-bletchley-park-03.jpg",\n "attachment_file": "rooms-england-bletchley-park-03.png"\n },\n "Francja_1": {\n "background_file": "rooms-france-paris-01.jpg",\n "attachment_file": "rooms-france-paris-01.png"\n },\n "Francja_2": {\n "background_file": "rooms-france-paris-02.jpg",\n "attachment_file": "rooms-france-paris-02.png"\n },\n "Francja_3": {\n "background_file": "rooms-france-paris-03.jpg",\n "attachment_file": "rooms-france-paris-03.png"\n },\n "Niemcy_1": {\n "background_file": "rooms-german-uboot-01.jpg",\n "attachment_file": "rooms-german-uboot-01.png"\n },\n "Niemcy_2": {\n "background_file": "rooms-german-uboot-02.jpg",\n "attachment_file": "rooms-german-uboot-02.png"\n },\n "Lwow_1": {\n "background_file": "rooms-poland-lwow-sknilow-01.jpg",\n "attachment_file": "rooms-poland-lwow-sknilow-01.png"\n },\n "Lwow_2": {\n "background_file": "rooms-poland-lwow-sknilow-02.jpg",\n "attachment_file": "rooms-poland-lwow-sknilow-02.png"\n },\n "Polska_1": {\n "background_file": "rooms-poland-warsaw-cipher-bureau-01.jpg",\n "attachment_file": "rooms-poland-warsaw-cipher-bureau-01.png"\n },\n "Polska_2": {\n "background_file": "rooms-poland-warsaw-cipher-bureau-02.jpg",\n "attachment_file": "rooms-poland-warsaw-cipher-bureau-02.png"\n },\n "Polska_3": {\n "background_file": "rooms-poland-warsaw-cipher-bureau-03.jpg",\n "attachment_file": "rooms-poland-warsaw-cipher-bureau-03.png"\n },\n "Polska_4": {\n "background_file": "rooms-poland-warsaw-cipher-bureau-04.jpg",\n "attachment_file": "rooms-poland-warsaw-cipher-bureau-04.png"\n }\n}'
- >>> print(json.dumps(places, indent=3))
- {
- "Anglia_1": {
- "background_file": "rooms-england-bletchley-park-01.jpg",
- "attachment_file": "rooms-england-bletchley-park-01.png"
- },
- "Anglia_2": {
- "background_file": "rooms-england-bletchley-park-02.jpg",
- "attachment_file": "rooms-england-bletchley-park-02.png"
- },
- "Anglia_3": {
- "background_file": "rooms-england-bletchley-park-03.jpg",
- "attachment_file": "rooms-england-bletchley-park-03.png"
- },
- "Francja_1": {
- "background_file": "rooms-france-paris-01.jpg",
- "attachment_file": "rooms-france-paris-01.png"
- },
- "Francja_2": {
- "background_file": "rooms-france-paris-02.jpg",
- "attachment_file": "rooms-france-paris-02.png"
- },
- "Francja_3": {
- "background_file": "rooms-france-paris-03.jpg",
- "attachment_file": "rooms-france-paris-03.png"
- },
- "Niemcy_1": {
- "background_file": "rooms-german-uboot-01.jpg",
- "attachment_file": "rooms-german-uboot-01.png"
- },
- "Niemcy_2": {
- "background_file": "rooms-german-uboot-02.jpg",
- "attachment_file": "rooms-german-uboot-02.png"
- },
- "Lwow_1": {
- "background_file": "rooms-poland-lwow-sknilow-01.jpg",
- "attachment_file": "rooms-poland-lwow-sknilow-01.png"
- },
- "Lwow_2": {
- "background_file": "rooms-poland-lwow-sknilow-02.jpg",
- "attachment_file": "rooms-poland-lwow-sknilow-02.png"
- },
- "Polska_1": {
- "background_file": "rooms-poland-warsaw-cipher-bureau-01.jpg",
- "attachment_file": "rooms-poland-warsaw-cipher-bureau-01.png"
- },
- "Polska_2": {
- "background_file": "rooms-poland-warsaw-cipher-bureau-02.jpg",
- "attachment_file": "rooms-poland-warsaw-cipher-bureau-02.png"
- },
- "Polska_3": {
- "background_file": "rooms-poland-warsaw-cipher-bureau-03.jpg",
- "attachment_file": "rooms-poland-warsaw-cipher-bureau-03.png"
- },
- "Polska_4": {
- "background_file": "rooms-poland-warsaw-cipher-bureau-04.jpg",
- "attachment_file": "rooms-poland-warsaw-cipher-bureau-04.png"
- }
- }
- >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement